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")); } }
🐳 作者:dupeng0811 📢 版权:本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接 💬 留言:同时 , 如果文中有什么错误,欢迎指出。以免更多的人被误导。 |
|