我们在Azure上部署了一个使用https的Web角色.由于这是我们希望用户访问系统的唯一方式,因此我们希望将访问http版本的用户转发到https版本.
我们在这里尝试过这些建议.
也就是说,我们在web.config中添加了以下内容:
<system.webServer>
<rewrite>
<rules>
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
</rule>
</rules>
</rewrite>
Run Code Online (Sandbox Code Playgroud)
但是,这似乎不起作用.有谁知道如何做到这一点?这似乎是一个共同的要求......
Kev*_*oet 22
Smarx刚刚再发一篇关于这篇文章的博客文章;)
http://blog.smarx.com/posts/redirecting-to-https-in-windows-azure-two-methods
如果网站发生故障,请点击摘要:
IIS URL重写
如果您不使用ASP.NET MVC但使用IIS(如在Web角色中),则可以使用默认安装的URL Rewrite模块.使用此模块重定向到HTTPS是相当简单的,并在其他地方记录,但让一切在本地计算模拟器中正常工作是非常重要的.特别是,您会发现大多数示例都假设HTTP流量始终位于端口80上,在计算模拟器下进行测试时并非总是如此.这是一个似乎在本地和云中工作的规则:
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect to HTTPS">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
<add input="{URL}" pattern="/$" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Redirect" url="https://{SERVER_NAME}/{R:1}" redirectType="SeeOther" />
</rule>
</rules>
</rewrite>
Run Code Online (Sandbox Code Playgroud)
小智 6
只是添加了Kevin Cloet对Smarx博客的回答.要仅在发布模式下设置RequireHttps属性,可以使用HttpContext.Current.IsDebuggingEnabled
public static void RegisterGlobalFilters(GlobalFilterCollection filters) {
if (!HttpContext.Current.IsDebuggingEnabled) {
filters.Add(new RequireHttpsAttribute());
}
}
Run Code Online (Sandbox Code Playgroud)
请参考此链接:https: //stackoverflow.com/a/27324439/1933168
| 归档时间: |
|
| 查看次数: |
12393 次 |
| 最近记录: |