I'm trying to solve the canonicalization issue

Discussion in 'ASP.NET 2.0' started by Bruce, Dec 1, 2008.

  1. Bruce

    Bruce DiscountASP.NET Staff

  2. Hi I'm trying to solve the canonicalization issue.

    If I put the following code in the global.asax file, it redirects from http://mysite.com to http://www.mysite.com/Default.aspx
    How can I get it to redirect to the root without the /Default.aspx and without causing an endless loop.

    Protected Sub Application_BeginRequest(ByVal sender As Object, ByVal e As System.EventArgs)
    If (HttpContext.Current.Request.Url.ToString().ToLower().Contains("http://mysite.com")) Then
    Dim myURL As String
    myURL = HttpContext.Current.Request.Url.ToString().ToLower()
    myURL = Replace(myURL, "http://mysite.com", "http://www.mysite.com")
    HttpContext.Current.Response.Status = "301 Moved Permanently"
    HttpContext.Current.Response.AddHeader("Location", myURL)
    End If
    End Sub

    thanks.
    Michael.
     
  3. Then you must have some other redirect code at play here. What is the site's default document, is it default.aspx? And is there any redirect logic there as well?

    Aristotle

    DiscountASP.NET
    www.DiscountASP.NET
     

Share This Page