如何在asp.net mvc中从https跳出到http模式
我通过在控制器操作上添加属性 [RequireSSL] 使我的登录页面启用了 Https,并且工作正常。但登录成功后仍处于https环境,但页面为非https页面。 谁能给我解决如何从 https 模式退出到 http 模式的问题吗? 在这方面的任何帮助将不胜感激。
I have made my Login page as Https enabled by adding the attribute [RequireSSL] on controller Action and it works fine. But after successful login it remains in https environment, however the page is non https page.
Can anybody give me workaround how to step out from https to http mode?
Any help in this regard will be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您基本上需要做相反的事情,即具有 [DoesNotRequireSSL] 属性,该属性实际上与 {RequireSSL] 属性相反,即重定向到 http 协议
另外,如果您想确保多个页面具有此行为,您可以设置一个基本控制器,所有非 http 控制器都可以从中继承,因此您不必担心必须为每个需要它的页面重复自己。
You basically need to do the opposite, which is have a [DoesNotRequireSSL] attribute, which effectively does the opposite of the {RequireSSL] attribute, i.e., redirect to http protocol
Also, if you would like to ensure that multiple pages have this behaviour, you can set up a base controller, from which all your non-http controllers can inherit from so you dont have to worry about having to repeat yourself for every page which needs this.
警告:我也有类似的问题。我学到的一件重要的事情是,在切换回 HTTP 后,您的 auth cookie 将通过纯文本发送。 请参阅此。
警告 2:不要忘记考虑可怕的您将被重定向到不安全的连接消息
如果您正在编写银行应用程序,则需要非常小心 - 并且还意识到公共 WiFi 连接上的用户数量不断增加,这些用户很可能[esily]通过一些偷偷摸摸的代理进行传输。对于主流网站来说,这可能是一个更大的问题,但也是我们所有人都应该意识到的问题。
另请参阅我的其他问题(当时没有答案写作 - 但后来我只是问了它!)
CAUTION: I had a similar question. One important thing I learnt was that your auth cookie will be sent over plain text after switching back to HTTP. See this.
CAUTION 2 : Don't forget to consider the dreaded You are about to be redirected to a connection that is not secure message
If you're writing a bank application you need to be real careful - and also realize the increasing number of users on public wifi connections that could well [esily] be funneled through some sneaky proxy. Probably a much bigger concern for mainstream sites but a concern for us all to be aware of.
See also my other question (no answers at time of writing - but then I only just asked it!)
我知道这是一个相当老的问题,但是上面提供的许多链接都已失效,此代码通过对系统中包含的
RequireHttpsAttribute
进行一些轻微修改来解决 ASP.NET MVC 5 的问题.Web.Mvc 命名空间:代码来自这篇文章,该文章还简要讨论了强制用户从 HTTPS 重定向到 HTTP 的一些安全问题。
I know this is quite an old question, but many of the links presented above are dead and this code addresses it for ASP.NET MVC 5 by making some slight modifications to the
RequireHttpsAttribute
that is included in the System.Web.Mvc namespace:The code comes from this article, which briefly discusses some of the security concerns of forcing users to redirect from HTTPS to HTTP as well.