welcome Netizen

Share Your Knowledge.It is a way to achieve immortality

Thursday, June 21, 2012

Redirect from Old URL to New URL link in

Here i share the code to redirect old URL link to new URL link, i have explained the case with some example

Take an example as below as old link used in website
Now i have deleted the page details.aspx, instead of details.aspx now i am using new page   user.aspx page URL is
Normally search engine crawl our old link so it always shows our Old link in search engine result. If the user comes to our website using
Old link we have to redirect the user to the correct page i.e. to new link.

To accomplish the above case we have to add the bit of code in Global.asax file
Add the below sub function in Global.asax file
VB.NET Code:

Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
        If System.Web.HttpContext.Current.Request.RawUrl.Contains("details.aspx") Then
            System.Web.HttpContext.Current.Response.Status = "301 Moved Permanently"
            System.Web.HttpContext.Current.Response.AddHeader("Location", "")
        End If
    End Sub
C# Code:

  If (HttpContext.Current.Request.RawUrl.Contains("details.aspx")) Then
        Response.Status = "301 Moved Permanently";
        Response.AddHeader("Location", "");

Keep Reading. Post your valuable comments


Post a Comment