Permanent Redirect in ASP.NET 4.0

In versions prior to ASP.NET 4.0, you could redirect between two pages, let us say from Default.aspx to About.aspx using Response.Redirect(“About.aspx”).

This caused an extra round trip to the server when users requested for Default.aspx and were then redirected to About.aspx. Moreover this is a temporary redirect (HTTP 302) as shown below using FireBug

image

ASP.NET 4.0 introduces the RedirectPermanent() helper method which avoids a round trip and is a permanent redirect (HTTP 301) as shown below

image

Use it as shown below:

Response.RedirectPermanent("About.aspx");

If you are new to Temporary and Permanent Redirect, read Redirects: Permanent 301 vs. Temporary 302






About The Author

Suprotim Agarwal
Suprotim Agarwal, Developer Technologies MVP (Microsoft Most Valuable Professional) is the founder and contributor for DevCurry, DotNetCurry and SQLServerCurry. He is the Chief Editor of a Developer Magazine called DNC Magazine. He has also authored two Books - 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook.

Follow him on twitter @suprotimagarwal.

1 comment:

Anonymous said...

Good post, but I cringe at the idea that a 301 does not require an additional trip to the server. The initial request requires the same amount of time as a 302, but it is often cached for future requests. In both cases, the browser requests the page; the server sends the response with the new URL; the browser then requests the new url. This is evident by your firebug screenshots.

The 301 redirect is cached and would probably not be called for future requests.