Links

 

HTTP 301 Redirect using C# / ASP.net

Why a 301 Redirect vs. Response.Redirect? A 301 redirect is a way to tell visitors and search engines, that a page has moved to a new location permanently. Response.Redirects calls are setup to fire 302 redirects, which indicate that a page has been moved temporarily. Google and some of the other search engines favor 301 redirects over 302, because it establishes a solid target for them to point at, and indicates that they do not have to reprocess the 302 redirect again in the near future.
public static void Redirect301(string Url) { var response = HttpContext.Current.Response; response.Clear(); response.Status = "301 Moved Permanently"; response.AddHeader("Location", Url); response.End(); }
One key thing in this code snippet is the response.End() call. This will ensure that if the call to this method is fired early in the code, none of the remaining logic on the page will be processed.
Submit a comment, suggestion, or additional information about this snippet
If you login or register, you'll be able to post a comment or provide feedback about this snippet.
Contact Us | Terms of Use