301 redirect Domain Name using global.asax

 

void Application_BeginRequest(object sender, EventArgs e)
{


if (HttpContext.Current.Request.Url.ToString().ToLower().Contains("http://domain.com"))
{
// new line here
HttpContext.Current.Response.Clear();
//
HttpContext.Current.Response.Status = "301 Moved Permanently";
HttpContext.Current.Response.AddHeader("Location", Request.Url.ToString().ToLower().Replace("http://domain.com", "http://www.domain.com"));
}


}

你可能感兴趣的:(redirect)