我最近将我的asp.net MVC网站切换到https,并希望所有现有通信都使用web重定向到https://www.example.com .config重写。Web.config重写http + www和http非www和https非www转到https:// www
我尝试了各种组合,但尚未成功。 需要处理以下三种情形:
http:// http://www https://
我最近将我的asp.net MVC网站切换到https,并希望所有现有通信都使用web重定向到https://www.example.com .config重写。Web.config重写http + www和http非www和https非www转到https:// www
我尝试了各种组合,但尚未成功。 需要处理以下三种情形:
http:// http://www https://
试试这个它可以帮助你:
<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="Permanent"
url="https://{HTTP_HOST}/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
感谢Praveen,但这不关心www我猜 – geekonweb
您可将您的流量使用Global.asax
以及使用https。
方法名称:Application_BeginRequest
您的代码重新定向将是这个样子
strProtocol = "https";
if (HttpContext.Current.Request.Url.ToString().ToLower().StartsWith("http:") == true)
{
Response.Redirect(strProtocol + "://" + strYourHostName + strYourRemainingURL, false);
}
你可以保持在web.config中的协议和主机名,并从那里挑选。
https://stackoverflow.com/questions/17714732/web-config-redirect-non-www-to-www/17715586#17715586可能有帮助 – Satpal