始终重定向到HTTPS [英] Redirect to HTTPS always

查看:86
本文介绍了始终重定向到HTTPS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有SSL证书并在我的一个网站上进行了配置。我想总是在https上导航我的网站,例如。

如果我使用www.mywebsite.com然后应该自动使用https

如果我使用http:// www.mywebsite.com然后应该自动使用https

如果我使用mywebsite.com然后应该自动使用https



我的网站托管于Windows Server 2003并使用IIS 6.0

I have SSL certificate and congigured on one of my website. I want to navigate my website always on https always, for eg.
if i use www.mywebsite.com then should use https automatically
if i use http://www.mywebsite.com then should use https automatically
if i use mywebsite.com then should use https automatically

My website is hosted on Windows Server 2003 and using IIS 6.0

推荐答案

我通过在Global.asax上添加一个简单的代码来实现这一点



I have achieve this by adding a simple code on Global.asax

protected void Application_BeginRequest(Object sender, EventArgs e)
    {
        if (HttpContext.Current.Request.IsSecureConnection.Equals(false) && HttpContext.Current.Request.IsLocal.Equals(false))
        {
            Response.Redirect("https://" + Request.ServerVariables["HTTP_HOST"]);
        }
    }


这篇关于始终重定向到HTTPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆