【发布时间】:2016-12-19 07:44:43
【问题描述】:
这个问题可能被问了一千遍,但我仍然找不到解决方案..
我有一个 .NET 应用程序,它在本地运行时会从 HTTP 重定向到 HTTPS。但是在 Azure Web App 中部署时,重定向将不起作用。
基于多个论坛帖子,我的重定向是使用Web.config 文件中的规则完成的。下面,您会看到此文件部署在 azure 上(我使用 ftp 检查过)
<system.webServer>
<staticContent>
<remove fileExtension=".woff" />
<mimeMap fileExtension=".woff" mimeType="application/font-woff" />
<remove fileExtension=".woff2" />
<mimeMap fileExtension=".woff2" mimeType="font/woff2" />
<remove fileExtension=".json" />
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
<rewrite>
<rules>
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
<add input="{HTTP_HOST}" pattern="([^/:]*?):[^/]*?" />
</conditions>
<action type="Redirect" url="https://{C:1}/{R:1}" redirectType="Permanent" />
</rule>
<rule name="static dist files" stopProcessing="true">
<match url="^(.+)$" />
<conditions>
<add input="{APPL_PHYSICAL_PATH}dist\{R:1}" matchType="IsFile" />
</conditions>
<action type="Rewrite" url="/dist/{R:1}" />
</rule>
<rule name="index.html as document root" stopProcessing="true">
<match url="^$" />
<action type="Rewrite" url="/dist/index.html" />
</rule>
</rules>
<!--<outboundRules>
<rule name="Add Strict-Transport-Security when HTTPS" enabled="true">
<match serverVariable="RESPONSE_Strict_Transport_Security"
pattern=".*" />
<conditions>
<add input="{HTTPS}" pattern="on" ignoreCase="true" />
</conditions>
<action type="Rewrite" value="max-age=31536000" />
</rule>
</outboundRules>-->
</rewrite>
</system.webServer>
这个Web.config文件是对原始Web.config文件转换的结果,因为在本地,HTTPS的端口设置为44362,因此本地使用的Web.config是有点不同:
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
<add input="{HTTP_HOST}" pattern="([^/:]*):[^/]*?" />
</conditions>
<action type="Redirect" url="https://{C:1}:44362/{R:1}"
redirectType="Permanent" />
</rule>
在本地,一切正常。重定向在瞬间完成。 但是,当部署在 azure Web 应用程序中时,不会发生重定向。 所以“---.azurewebsites.net”不会自动重定向到“https://---.azurewebsites.net”
但我可以看到,他达到了 te 规则,因为浏览器选项卡的标题瞬间以该规则的名义重命名。
如果有人发现此代码中的愚蠢错误,请告诉我。
问候,
【问题讨论】:
标签: .net azure ssl https azure-web-app-service