ASP.NET 4.0 Features : Page RedirectParmanent

Abhi2434
Posted by in ASP.NET category on for Beginner level | Views : 12048 red flag
Rating: 1 out of 5  
 1 vote(s)

The article discusses one of the new feature introduced with .NET 4.0 which enable you to Redirect your page for Search Engine
Introduction
.NET 4.0 introduces a new concept to redirect your page from one location to another.  From the early days, you have been using Response.Redirect / Server.Transfer. While Server.Transfer doesnt seem to send any information about redirection to search engine, Response.Redirect redirects a page and sends 302 as its response Code. The response code 302 identifies that the transfer is a temporary and therefore, the Search Engine entry will never be updated. But in certain cases when you require the search page to redirect it permanently. You might want the search result to show the new page rather than the old page which redirects to the new page. Here lies the requirement of this new method Response.RedirectParmanent.





Main Objective of Response.RedirectParmanent
Response.RedirectParmanent works in similar fashion as to Response.Redirect. The only difference is its Response code.

Method                      Response Code                  Meaning

Redirect()                  302                                  Response is Redirected temporarily and Search Engine Doesn't need to change its entry
RedirectParmanent()    301                                  Redirect is parmanent, and Search engine will update the old entry with the new one.
Server.Transfer()        200                                  No redirection code is sent, and Search Engine will think the response is coming from the same page.

From the above table, it is clear that Search engine will only update its entry when we use RedirectParmanent.

Implementation
You must know that this method is introduced in ASP.NET 4.0, so if you are in previous version, you can use :

public static class Extensions
{
public static void RedirectPermanent(this HttpResponse Response,
string absoluteUri)
{
Response.Clear();
Response.Status = "301";
Response.RedirectLocation = absoluteUri;
Response.End();
}
}

This Extension will add the RedirectParmanent to your application.

Usage

  • Response.Redirect is perfect when your page is temporarily changed and will again be reverted to original within a short span of time.
  • Response.RedirectParmanent() when you are thinking of deleting the original page totally after the search engines changes its database. 
  • Server.Transfer() when you are thinking of keeping the page for ever, and to let search engine unaware of this redirection.

Conclusion
To Conclude, I must be thankful that the method is added permanently to the Framework. Hence, I dont need to write my own extension. Use it gracefully and only when it is required. There are lots of other features as well, I hope I would try to discuss each of them in my next series of articles.

Thanks for Reading.
Page copy protected against web site content infringement by Copyscape

About the Author

Abhi2434
Full Name: Abhishek Sur
Member Level: Silver
Member Status: Member,Microsoft_MVP,MVP
Member Since: 12/2/2009 4:19:08 AM
Country: India
www.abhisheksur.com
http://www.abhisheksur.com
Working for last 2 and 1/2 years in .NET environment with profound knowledge on basics of most of the topics on it.

Login to vote for this post.

Comments or Responses

Posted by: Rajni.Shekhar on: 4/9/2012 | Points: 25
Hi,
Nice article, i have tried it in 3.5
but it is showing run time error: "HTTP status string is not valid." at the line : response.Status = "301";

Please suggest.

Login to post response

Comment using Facebook(Author doesn't get notification)