Understanding ASP.NET Response.Redirect

1 minute read

ASP.NET has a wonderful carry over from Classic ASP that many developer still use:

Response.Redirect(string url);

When ASP.NET encounters a Redirect() request it will internally throw a thread abort exception and immediately send headers back to the client (typically a browser) to go to another URL.

There are a couple of things to be aware about when you use Response.Redirect():

1. Internally a ThreadAbort exception is thrown. This is normal and if you monitor your CLR exceptions and use Response.Redirect() – you will see exceptions in the event counters.

2. Response.Redirect sets an HTTP 302 header along with the URL to be redirected to.

The SEO tip has to do with the HTTP status code that ASP.NET sends back. The 302 status code essentially says, “this item has moved temporarily”. Search engines crawling your site are not guaranteed to follow 302 redirects, nor should they. By following a 302 the search engine could incorrectly index the location of content.

However, there are cases where you do want search engines to follow the redirect because it’s a permanent redirect. In these cases you want to set an HTTP 301 header. The 301 header essentially says, “this item has moved permanently”.

Here is how:

if (send301) {

Response.AddHeader(“Location”, url);

Response.StatusCode = 301;

} else {

Response.Redirect(url);

}

Related articles:

Want to receive more great content like this for free?

Subscribe to our newsletter to get best practices, recommendations, and tips for digital marketers
Page Not Found

Sorry, we didn't find anything for the requested URL

The URL you requested is managed by DailyStory. While we manage lots of awesome content for our customers, we don't have anything for this URL.

This could have happened for a variety of reasons:

  • The content was removed by the customer. Hey it happens.
  • It never existed - maybe a typo in your URL?
  • Something went wrong on our end. Unlikely, but sorry :(

If this is unexpected, please feel free to contact us.