【发布时间】:2011-09-16 05:15:12
【问题描述】:
我已经在我的应用程序上实现了 https,现在我正试图让 IIS 将所有 http 请求重定向到 https,这样用户甚至都不会注意到这个变化。
我已经更改并尝试了一些 IIS 选项,但没有成功。
我该怎么做?
我使用的是 IIS 7.5 和 ASP.NET 2.0
问候,
【问题讨论】:
我已经在我的应用程序上实现了 https,现在我正试图让 IIS 将所有 http 请求重定向到 https,这样用户甚至都不会注意到这个变化。
我已经更改并尝试了一些 IIS 选项,但没有成功。
我该怎么做?
我使用的是 IIS 7.5 和 ASP.NET 2.0
问候,
【问题讨论】:
blog article 中描述的方法效果很好。
总结:
1) 打开网站的“需要 SSL”设置。
2) 在 403 错误的错误设置配置中,将其设置为“使用 302 重定向响应”,并将新 URL 设置为带有 https:// 前缀的完整 URL。
@987654324 @
【讨论】:
您可以安装RewriteModule 并按照this page 上的说明进行操作。
您可以在 global.asax 上的 beginRequest 上进行简单检查,类似于以下代码:
protected void Application_BeginRequest(Object sender, EventArgs e)
{
HttpApplication app = (HttpApplication)sender;
if(!app.Response.Request.IsSecureConnection)
{
app.Response.Redirect(Request.RawUrl.Replace("http://","https://"), true);
return;
}
}
ps。我没有检查这个代码,我现在就输入它。
【讨论】:
void global_asax_BeginRequest(object sender, EventArgs e) { HttpApplication app = (HttpApplication)sender; if (!app.Request.Url.AbsoluteUri.StartsWith("https")) { app.Response.Redirect(Request.Url.AbsoluteUri.Replace("http://", "https://"), true); } }
在 IIS 7 中从 HTTP 重定向到 HTTPS
URL Rewrite 与 IIS Manager 紧密集成以便更好地管理(从https://go.microsoft.com/?linkid=9722532 下载)
配置规则设置
匹配网址标签:
name= 重定向 2 HTTPS
url= (.*)
条件标签:添加记录
输入= {HTTPS}
模式= ^OFF$
操作标签:
type= 重定向
重定向 URL= https://{HTTP_HOST}/{R:1}
redirectType=永久
【讨论】: