Sep 15, 2010

Redirect Permanent from a non-www to a www using ASP.NET

Please add below code into your global.aspx file

protected void Application_BeginRequest(object sender, EventArgs e)
{
if (Request.Url.Authority.StartsWith("www"))
return;

var url = string.Format("{0}://www.{1}{2}",
Request.Url.Scheme,
Request.Url.Authority,
Request.Url.PathAndQuery);

Response.Redirect(url,true);
}

No comments:

Post a Comment