• 网站301跳转


      源码:

            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

      在Global里写好逻辑,网站运行的时候会首先进入Global,这里介绍的是http如何跳https.  

      

    这是我的另一个博客,欢迎访问

  • 相关阅读:
    CSS3选择器
    在sublimen中整理CSS代码及其兼容性问题
    sublime 插件安装
    sublime 使用快捷键
    HTML5标签选择,图文混排使用dl dt dd
    HTML布局
    分页器
    Django ==> Form 组件
    Django ==> ModelAdmin
    前端 ==> Ajax
  • 原文地址:https://www.cnblogs.com/sunshine-wy/p/9560079.html
Copyright © 2020-2023  润新知