Oct 6, 2010

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

Please add below code into your global.aspx file

protected void Application_BeginRequest(object sender, EventArgs e)
{
string server = Request.ServerVariables["SERVER_NAME"];
if (server != "localhost")
{
if (!Request.Url.ToString().ToLower().Contains("www.") || !Request.Url.ToString().ToLower().Contains("http://"))
{
Response.Redirect("http://www." + server + Request.Path, true);
}
}

}

No comments:

Post a Comment