ASP.NET MVC3 实现全站重定向的简单方法
内容摘要
MVC3用以下代码实现全站重定向复制代码 代码如下:protected void Application_BeginRequest(object sender, EventArgs e) { string strUrl = Request.Ur
文章正文
MVC3用以下代码实现全站重定向
复制代码 代码如下:
protected void Application_BeginRequest(object sender, EventArgs e)
{
string strUrl = Request.Url.ToString().Trim().ToLower();
if (strUrl.Contains("http://phpstudy.net"))
{
Response.RedirectPermanent(strUrl.Replace("http://phpstudy.net", "http://www.phpstudy.net"));
}
}
实现如:http://phpstudy.net/about 重定向到 http://www.phpstudy.net/about
代码注释