Single subdomain
You will probably want the site to have one adress for each page, not with and then without www. I tend to fix this by placing following code snippet inside the Global.asax.cs file:
protected void Application_BeginRequest (object sender, EventArgs e)
{
if (!Request.Url.Host.StartsWith ("www") && !Request.Url.IsLoopback)
{
var builder = new UriBuilder (Request.Url);
builder.Host = "www." + Request.Url.Host;
Response.StatusCode = 301;
Response.AddHeader ("Location", builder.ToString ());
Response.End ();
}
}
This code will redirect the user to the www domain if they are currently accessing site without it.
Published: 2016-08-25