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



Will you give this article a +1 ? Thanks in advance




About The Author

Suprotim Agarwal, ASP.NET Architecture MVP works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He has also written an EBook 51 Recipes using jQuery with ASP.NET Controls.

Follow him on twitter @suprotimagarwal

comments

1 Response to "Permanent Redirect in ASP.NET 4.0"
  1. Anonymous said...
    May 23, 2010 at 9:28 AM

    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.

 

Copyright © 2009-2014 All Rights Reserved for DevCurry.com by Suprotim Agarwal | Terms and Conditions