301 redirect page in asp.net
Saturday 12 September 2009
To create a 301 redirect page in asp.net, simple use the below code:
- Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
- Dim strNewURL = "http://www.wallaceit.co.uk"
- Response.Status = "301 Moved Permanently"
- Response.AddHeader("Location", strNewURL)
- 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:
-
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
-
Dim strNewURL As String = "/newpage" & Request.QueryString("id") & ".aspx"
-
Response.Status = "301 Moved Permanently"
-
Response.AddHeader("Location", strNewURL)
-
End Sub
You could also query a database if necessary to pull down titles etc if you've used URL rewriting
|
(0)
|
|
|