网站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.  

  

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值