301 redirect page in asp.net




301 redirect page in asp.net
To create a 301 redirect page in asp.net, simple use the below code:
  1. Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)   
  2.         Dim strNewURL = "http://www.wallaceit.co.uk"  
  3.         Response.Status = "301 Moved Permanently"  
  4.         Response.AddHeader("Location", strNewURL)   
  5. End Sub  
Obviously you would change our domain name for the relavent new page location.
 
If your pages are loaded from a database, you might consider code like below:
  1. Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)   
  2.         Dim strNewURL As String = "/newpage" & Request.QueryString("id") & ".aspx"  
  3.         Response.Status = "301 Moved Permanently"  
  4.         Response.AddHeader("Location", strNewURL)   
  5. End Sub  
You could also query a database if necessary to pull down titles etc if you've used URL rewriting

1 person likes this article, click here to say you like this article too (1)
Send a link to this page via email Send a link to this page