我有ASP.NET MVC的Web应用程序。https默认ASP.NET MVC
当我把它上传到Azure上的Web应用程序,网站上有http://
我需要它是https://
始终。
我该怎么做?
我知道这可能是太广泛的问题,但你能给我一些建议吗?
我设置这样的属性在我的项目
我有ASP.NET MVC的Web应用程序。https默认ASP.NET MVC
当我把它上传到Azure上的Web应用程序,网站上有http://
我需要它是https://
始终。
我该怎么做?
我知道这可能是太广泛的问题,但你能给我一些建议吗?
我设置这样的属性在我的项目
我需要它是https://开头总是这样。
您可以尝试创建URL重写规则以强制执行HTTPS。
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<!-- BEGIN rule TAG FOR HTTPS REDIRECT -->
<rule name="Force HTTPS" enabled="true">
<match url="(.*)" ignoreCase="false" />
<conditions>
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
<!-- END rule TAG FOR HTTPS REDIRECT -->
</rules>
</rewrite>
</system.webServer>
</configuration>
你也可以参考Enforce HTTPS on your app。
如果您更喜欢通过代码解决方案而不是web.config,您可以在Global.asax.cs文件中编写以下代码。
protected void Application_BeginRequest() {
// Ensure any request is returned over SSL/TLS in production
if (!Request.IsLocal && !Context.Request.IsSecureConnection) {
var redirect = Context.Request.Url.ToString().ToLower(CultureInfo.CurrentCulture).Replace("http:", "https:");
Response.Redirect(redirect);
}
}
谢谢它也有帮助 –
感谢这有助于 –