ASP. NET MVC3 a simple way to achieve full station redirection

  • 2020-11-03 22:04:32
  • OfStack

MVC3 implements full site redirection with the following code


protected void Application_BeginRequest(object sender, EventArgs e)
        {
            string strUrl = Request.Url.ToString().Trim().ToLower();
            if (strUrl.Contains("http://ofstack.com"))
            {
                Response.RedirectPermanent(strUrl.Replace("http://ofstack.com", "https://www.ofstack.com")); 
            }
        }

Implementation: http: / / ofstack com/about redirected to https: / / www ofstack. com/about


Related articles: