在IIS 7.5上运行的ASP.NET应用程序上强制Https

前端之家收集整理的这篇文章主要介绍了在IIS 7.5上运行的ASP.NET应用程序上强制Https前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在我的web.config文件中使用以下代码在我的整个站点上强制使用SSL; @H_502_2@<system.webServer> <rewrite> <rules> <rule name="Redirect HTTP to HTTPS" stopProcessing="true"> <match url="(.*)"/> <conditions> <add input="{HTTPS}" pattern="^OFF$"/> </conditions> <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther"/> </rule> </rules> </rewrite> </system.webServer>

但我想做的是强制ssl只有〜/ purchase /和〜/ account / path并在它们下面.该匹配网址应该是什么?

注意正则表达式在这里也适用于我和通配符.

解决方法

您应该使用此模式(这将适用于/ purchase / something以及/ account / something-else): @H_502_2@^((purchase|account)/.*)$

你必须记住,该URL应该没有前导斜杠/.

@H_502_2@<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="Force HTTPS" stopProcessing="true"> <match url="^((purchase|account)/.*)$" /> <conditions> <add input="{HTTPS}" pattern="^OFF$" /> </conditions> <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" /> </rule> </rules> </rewrite> </system.webServer> </configuration>

猜你在找的asp.Net相关文章