Response.Redirect in Windows Azure
I’ve recently created an application called GetGravatar that allows you to update your Twitter profile picture with your Gravatar. Once I’d set up my Windows Azure custom domain name I decided I wanted the web address for this new service site to be without “www” as seems to be all the rage (to keep the web address short). So, I looked at doing a Response.Redirect to catch any attempts to access my domain with “www” in it. I’m very sure that there are better ways of doing this but I added the following to my Site.master file:
if (Request.Url.ToString().StartsWith("http://www."))
{
Response.StatusCode = (int)System.Net.HttpStatusCode.MovedPermanently;
string responseUrl = Request.Url.ToString().Replace("http://www.", "http://");
Response.Redirect(responseUrl, true);
}
So, if somebody types in http://www.getgravatar.com (see it works) or anything with a “www.” in the URL they will be redirected to a non-www page. However, the redirect seemed to go to the correct URL but with port 20000. I’ve no idea why this is so I had to add a special case in to remove the port.
if (Request.Url.ToString().StartsWith("http://www."))
{
Response.StatusCode = (int)System.Net.HttpStatusCode.MovedPermanently;
string responseUrl = Request.Url.ToString().Replace("http://www.", "http://");
responseUrl = responseUrl.Replace(":20000", "");
Response.Redirect(responseUrl, true);
}
I’ve not read up to see if this is expected but I thought it was quite unexpected and may be of use to somebody else in the future.
Related posts:
About Phil Leggetter
My name is Phil Leggetter and I'm a Developer Evangelist at Pusher, a Real-Time Web Software and Technology Evangelist and Consultant, software engineer, team leader, line manager, micropreneur, product developer, Twitter user and a keen user of social media. For more information see the About Phil Leggetter page.
Social
Tags
.NET Ajax API APIs ASP.NET MVC Bing Blogging C# cloud comet Community DataSift Facebook Google Hardware http streaming ian sanders ideas Internet JavaScript Kwwika Life Mapping Microsoft Mobile Phones pubsubhubbub pusher real-time real-time data real-time push real-time web realtime RSS RTRIA Scotland silverlight Social Media Software Development Superfeedr truly real-time truly real-time web Twitter web 2.0 websockets Whinge









