Online Design and Development 
Better Design, Better Hosting, Better Service ...

Today is:
21 November 2008
 
Home arrow Articles arrow How To arrow How to do a 301 Redirect in ASP.net using Visual Basic
 
 
 
  :: Main Menu
Main Menu
Home
News
Articles
Design Portfolio
Hosting Packages
Help Desk
Support Forums
Server Status
Contact Us
Login Form





Lost Password?
No account yet? Register
 
 
How to do a 301 Redirect in ASP.net using Visual Basic

So you have a new domain or you have changed the structure of your website but you don't want your visitors to get the dreaded 404 page because the page they are looking for no longer exists.

The best thing you can do is setup a 301 redirect to the pages new location. The 301 redirect accomplishes two things, one it tells all of the search engines that the page has been moved permantly to a new location and second it automatically redirects your user to the new page.

By using a 301 redirect you will make sure that your new page retains the same page ranking with the search engines and most importantly allow your visitors to find what the correct content. On to the code...

Insert the following code into the head of your aspx page. You also need to add a form tag to the page with the runat="server" setup. Please remember this is setup for an asp.net page using visual basic, not C#.



Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  Response.Status = "301 Moved Permanently"
  Response.AddHeader("Location","http://www.yoursite.com/yourpage.htm")
End Sub