标签:
一些朋友可能会使用比较苯的方法,在每个 Controller 下都加上 Response.RedirectPermanent 方法。
较为简单的做法是在 Global.axax.cs 中加入下边的代码
/// <summary>
/// 301永久重定向不带www域名到带www的域名
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Application_BeginRequest(object sender, EventArgs e)
{
string strUrl = Request.Url.ToString().Trim().ToLower();
if (strUrl.Contains("http://baidu.net"))
{
Response.RedirectPermanent(strUrl.Replace("http://baidu.net", "http://www.baidu.net")); //good
}
}
MVC 301重定向(永久重定向不带www域名到带www的域名)
标签:
原文地址:http://www.cnblogs.com/caoxilong/p/4571024.html