ASP.NET MVC3 实现全站重定向的简单方法


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


« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3