如何解决ASP.NET MVC外部登录将URi从http重定向到https
我在MVC项目中使用Microsoft.Owin。 将项目发布到服务器后,用于Google和Facebook的重定向URL附带[http],但是我的域是[https]。 我在线尝试了所有可用的解决方案,但没有结果。
错误的解决方案: 在web.config中
<rewrite>
<rules>
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="on" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Found" />
</rule>
</rules>
</rewrite>
错误的解决方案: 在gloabal.asax
Protected Sub Application_BeginRequest()
If Not Context.Request.IsSecureConnection Then Response.Redirect(Context.Request.Url.ToString().Replace("http:","https:"))
End Sub
错误的解决方案: 在startup.auth
中.OnApplyRedirect = Sub(context)
Dim redirectUri = New Uri(context.RedirectUri,UriKind.Absolute)
If redirectUri.Scheme = "http" And redirectUri.Host = context.Request.Uri.Host Then
context.RedirectUri = "https://xxxx/signin-google"
End If
End Sub
注释:
- 在我的本地计算机上,重定向URi将作为https
- 我的服务器在cloudflare CDN下
解决方法
您的web.config
解决方案中存在错误。根据您的情况,该模式应为off
,否则它将仅在URL已经是HTTPS时才评估。像这样。
<rewrite>
<rules>
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Found" />
</rule>
</rules>
</rewrite>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。