In global.asax:
protected void Application_BeginRequest(Object sender, EventArgs e)
{
if (Request.Url.Authority.StartsWith("www"))
return;
string url = (Request.Url.Scheme
+ "://www."
+ HttpContext.Current.Request.Url.Authority
+ HttpContext.Current.Request.Url.AbsolutePath
);
Response.Clear();
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location", url);
Response.End();
}
Source: stackoverflow
No comments:
Post a Comment