[英]Host ASP.NET CORE on IIS with SSL
我有一個使用SSL證書托管在IIS上的應用程序。 使用標准ASP,我可以在web.config
配置重寫以自動重定向到SSL版本。
但是我該怎么做呢? 我希望當有人通過HTTP打開鏈接時,他們將自動重定向到HTTPS。
非常感謝!
您仍然可以(並且應該)使用web.config
IIS處理SSL后,您的應用程序(Kestrel)就會收到“干凈的” HTTP,因此現在檢查代碼中的SSL連接為時已晚。 您需要將IIS配置為從http
重定向到https
。
我使用此web.config
(在Azure中可用):
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
<rewrite>
<rules>
<clear />
<rule name="Redirect to https" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
在Asp.Net 2.1及更高版本中,只需在startup.cs中將以下內容添加到應用程序的Configure方法中:
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
// other app configure code here
app.UseHttpsRedirection();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.