源码:

        protected void Application_BeginRequest(object sender, EventArgs e)
        {
            HttpApplication application = sender as HttpApplication;
            HttpContext context = application.Context;
            HttpRequest request = context.Request;
            HttpResponse response = context.Response;
            if (request.Url.Scheme != "https")
            {
                Page301Url(response, "https://" + request.Url.Host + request.RawUrl);
            }
        }
        protected void Page301Url(HttpResponse response, string url301)
        {
            response.Clear();
            response.Cache.SetCacheability(HttpCacheability.NoCache);
            response.Cache.SetExpires(DateTime.UtcNow.AddYears(-1));
            response.Cache.SetMaxAge(TimeSpan.Zero);
            response.Cache.SetNoServerCaching();
            response.Cache.SetNoStore();
            response.Cache.SetNoTransforms();
            response.Cache.SetProxyMaxAge(TimeSpan.Zero);
            response.StatusCode = (int)HttpStatusCode.MovedPermanently;
            response.AddHeader("Location", url301);
            response.End();
        }
View Code

相关文章:

  • 2021-10-16
  • 2022-12-23
  • 2022-12-23
  • 2021-11-01
  • 2022-01-04
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-15
  • 2021-11-11
  • 2022-12-23
  • 2022-02-18
  • 2021-09-18
  • 2021-10-05
  • 2021-07-29
相关资源
相似解决方案