title: Redirecting to www
body: <p>I've added a global.asax to my web project, and I'm trying to check if the domain in the <code>Begin_Request</code> contains "www", and if it doesn't, then redirect them to the page they were requesting, but with the "www" pre-pended to it.  For an example, If I try to access : SampleSite.com, it directs me to SampleSite.com/www.SampleSite.com/www.SampleSite.com/www.SampleSite.com/www.SampleSite.com/www.SampleSite.com/www.SampleSite.com/www.SampleSite.com/index.aspx</p>
  
  <p>Here is the code:</p>
  
  <pre><code>&lt;script runat="server"&gt;
      Sub Begin_Request(ByVal sender As Object, ByVal e As EventArgs) Handles Me.BeginRequest
          Dim domain As String = Request.Url.Host
          If (Not domain.StartsWith("www")) Then
              Dim path As String = ""
              path = String.Format("www.{0}", Request.Url.AbsoluteUri.Substring(7))
              Response.Redirect(path)
          End If
  
      End Sub
  &lt;/script&gt;
  </code></pre>
  
  <p>Any ideas?</p>