站长资源网络编程

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

整理:jimmy2026/8/5浏览2
简介MVC3用以下代码实现全站重定向复制代码 代码如下:protected void Application_BeginRequest(object sender, EventArgs e) { string strUrl = Request.Url.ToString

MVC3用以下代码实现全站重定向
复制代码 代码如下:
protected void Application_BeginRequest(object sender, EventArgs e)
        {
            string strUrl = Request.Url.ToString().Trim().ToLower();
            if (strUrl.Contains("http://jb51.net"))
            {
                Response.RedirectPermanent(strUrl.Replace("http://jb51.net", "https://www.jb51.net"));
            }
        }

实现如:http://jb51.net/about 重定向到 https://www.jb51.net/about