Click here to Skip to main content
Click here to Skip to main content

Comparision between Response.Redirect, Response.RedirectParmanent and Server.Transfer

, 10 Sep 2009 CPOL
Rate this:
Please Sign up or sign in to vote.
It is to be noted, .NET has lately introducedResponse.RedirectParmanent() after a long await. The main motive of this is tohave permanent response redirection to the Search Engines.Response.RedirectParmanent() is an extension function introduced in .NET 4.0.Themain motive of it is to indicate

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. The Response.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.

When to use:

  • 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

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Abhishek Sur
Architect
India India
Did you like his post?
 
Oh, lets go a bit further to know him better.
Visit his Website : www.abhisheksur.com to know more about Abhishek.
 
Abhishek also authored a book on .NET 4.5 Features and recommends you to read it, you will learn a lot from it.
http://bit.ly/EXPERTCookBook
 
Basically he is from India, who loves to explore the .NET world. He loves to code and in his leisure you always find him talking about technical stuffs.
 
Presently he is working in WPF, a new foundation to UI development, but mostly he likes to work on architecture and business classes. ASP.NET is one of his strength as well.
Have any problem? Write to him in his Forum.
 
You can also mail him directly to abhi2434@yahoo.com
 
Want a Coder like him for your project?
Drop him a mail to contact@abhisheksur.com
 
Visit His Blog

Dotnet Tricks and Tips



Dont forget to vote or share your comments about his Writing
Follow on   Twitter   Google+

Comments and Discussions

 
QuestionThere are so many mistakes in this article Pinmemberkaradetito16-Sep-13 22:44 
GeneralMessage Automatically Removed PinmemberLalit24rocks15-May-13 20:18 
Questionwhat you mean by search engine PinmemberFahim saqib18-Nov-12 19:53 
Hi i am new in asp.net Please Clear the search engine means like google , yahoo or
 
here its different meaning related to search functionality of a particular site  
 
Smile | :)
GeneralMy vote of 3 PinmemberFahim saqib18-Nov-12 19:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.141015.1 | Last Updated 10 Sep 2009
Article Copyright 2009 by Abhishek Sur
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid