Take the 2-minute tour ×

Our asp application is moving to new server and i want to implement a permenant url redirection. I am aware of following two approaches , i need to understand which one to user over other and when ?

Option 1:

<%@ Language=VBScript %><% Response.Redirect "http://www.example.com" %>

Option 2:

  Response.AddHeader "Location","http://www.example.com/" %>



share|improve this question
add comment

4 Answers

Response.Redirect issues a 302, which is a temporary redirect. 301, using the Response.AddHeader that you listed, is for permanent redirects.

The differences between 301 and 302 have some importance with search-engine-optimization. A 301 will hold all of your search rankings from the old location. On the flip side, if you DON'T want your new page to be indexed, you can use a Response.Redirect (302) since the engines will consider the redirect temporary. Google doesn't index 302's because a lot of spammers use it to try to increase their rankings.

Since you're permanently moving to a new server, a 301 is the best way to go.

share|improve this answer
add comment

Response.Redirect() (and the equivalent method RedirectPermanent() for a 301) does a lot of things behind the scenes. It null checks the requested URL string, encodes it, calls the event handlers for the Redirecting event if there are any, and finally calls Response.End(), which flushes the response back to the browser and aborts the current thread.

Ultimately, you probably won't notice much difference between setting headers manually and calling redirect.

Incidentally, there are more (and better) options for handling this. IIS has a URL Rewriting module, which would let you redirect a given URL without ever calling your page as a request handler, and centrally manage your URL's for easier management of search engines.

share|improve this answer
This is not correct. See my answer for details. –  Charles Boyung Jun 11 '10 at 19:08
What is not correct here? –  womp Jun 11 '10 at 19:12
Exactly what I said in my answer. There is no way to have Response.Redirect do a 301. –  Charles Boyung Jun 11 '10 at 19:17
You call Response.RedirectPermanent(). It just calls Response.Redirect(). Either way, how is my answer wrong? –  womp Jun 11 '10 at 19:21
It does not call Response.Redirect internally. What in the world are you talking about? They both set headers and response status - neither one calls the other one. –  Charles Boyung Jun 11 '10 at 19:25
show 2 more comments

A normal redirect will by default use HTTP status 302. A redirect with status 301 will not be indexed by searchbots (like Googlebot) and if they were, they will be removed from existing indexes. Very useful if you want to "update" an old URL to a newer URL. The searchbot will index redirects with status 302 anyway, so you may likely end up with pollution in search results. You'd normally use status 302 for for example PRG pattern and status 301 for permanent redirects like as you're doing now.

share|improve this answer
add comment

Response.Redirect sends a "302 - moved temporarily" status code to the browser, which may or may not be okay depending on what you are doing. If you are redirecting to the correct location for your content, you want to do the 301 redirect because search engines will not crawl properly against a 302.

share|improve this answer
This is not 100% correct. Response.Redirect only sends a 302 if you set the "permanent" flag to false. It can send either a 301 or 302. He has the option of doing both, he doesn't need to manually set the headers to send a 301. –  womp Jun 11 '10 at 19:13
@womp - you have absolutely no idea what you are talking about. There is no "permanent" flag. The Response.Redirect function takes one or two parameters - target URL and optionally a boolean to end the response. Please educate yourself: msdn.microsoft.com/en-us/library/a8wa7sdt.aspx –  Charles Boyung Jun 11 '10 at 19:17
@womp - In case you can't read that whole page - here's the important part for you - "ASP.NET performs the redirection by returning a 302 HTTP status code." –  Charles Boyung Jun 11 '10 at 19:19
You're taking the question way more literally than I am. He can use Response.RedirectPermanent() if he wants to send a 301. I interpreted his question as "set headers manually or use redirect?". You still haven't said what was wrong with my answer. –  womp Jun 11 '10 at 19:20
@womp - He asked specifically about Response.Redirect vs. setting response headers. Your answer is completely wrong in that regard. You also made no reference to that function in your answer at all. And Response.RedirectPermanent is brand new to Asp.Net 4.0, so its actually pretty likely that he isn't using that, otherwise he would have referred to that. –  Charles Boyung Jun 11 '10 at 19:22
show 5 more comments

Your Answer


