Friday 21 March 2014

Response.Redirect, Response.RedirectParmanent and Server.Transfer

Response.Redirect, Response.RedirectParmanent and Server.Transfer




It is to be noted, .NET has lately introduced Response.RedirectParmanent() after a long await. The main motive of this is to have permanent response redirection to the Search Engines.

Response.RedirectParmanent() is an extension function introduced in .NET 4.0.
The main motive of it is to indicate the Response Code to the Search Engine that the page is moved permanently. TheResponse.Redirect generates Response code as 302 whereas RedirectParmanent returns 301.

Thus say you have a page, and which is included to search engine for a long time, if you use Response.Redirect() it will not change this effect to the search engine(taking this a temporary change), while if you use Response.RedirectParmanent() it will take it as permanent.

If you want to write Response.RedirectParmanent() yourself the code will look like :
public static class Extensions
{
   public static void RedirectPermanent(this HttpResponse Response, 
                                         string absoluteUri)
   {
       Response.Clear();
       Response.Status = "301";
       Response.RedirectLocation = absoluteUri;
       Response.End();
   }
}

In case of Server.Transfer() the actual response is actually been updated. There is no effect to the search engine, and search engine will think the output is coming from the same page that is called. Let us give an example :
Say you have 2 pages (Page1 and Page2) where Page1 redirects to Page2.
In case of

1. Response.Redirect() : Search Engine will take this redirection as Temporary(Status 301) and always keep Page1 in its cache.

2. Response.RedirectParmanent() : Search Engine will take this a permanent redirection(Status 302) and will remove Page1 from its database and include Page2 for better performance on search.

3. Server.Transfer() : Search Engine will be unaware of any redirection been took place (Status 200) and will keep Page1 to its database. It will think Page1 is producing the output response of Page2.

exp.

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
ASP.NET 4.0 introduces some SEO improvements. Response has now new method calledRedirectPermanent(). This method performs same redirect as Response.Redirect() but it uses response code 301. You can find more information about HTTP response codes from HTTP 1.1 specification, chapter 10. Status Code Definitions.
Response.Redirect() returns 302 to browser meaning that asked resource is temporarily moved to other location. Permanent redirect means that browser gets 301 as response from server. In this case browser doesn’t ask the same resource from old URL anymore – it uses URL given by Location header.

Benefit of HTTP code 301:
  • Code 301 means the requested URL (page1.aspx) is moved permanently to (page2.aspx)


  • This code is used by search engine crawlers to update the search index to the new moved information. Search engines like Google and Bing work on the rank of the new page if this status code is seen


  • It informs the search engine that the page location has moved permanently, and it needs to index the page from the new location in the future.

No comments:

Post a Comment