使用 ASP.NET MVC 应用程序重定向远离 HTTPS
我正在使用 ASP.NET MVC 2,并且有一个通过 HTTPS 保护的登录页面。为了确保用户始终通过 SSL 访问这些页面,我已将属性 [RequireHttps]
添加到控制器。这完美地完成了工作。
当他们成功登录后,我想将他们重定向回 HTTP 版本。但是,没有 [RequireHttp]
属性,我正在努力思考如何实现这一目标。
增加的(潜在的)复杂性是,网站在生产时托管在域的路由上,但出于开发和测试目的,它位于子目录/虚拟目录/应用程序中。
我是否想得太多了?有没有一个简单的解决方案摆在我面前?还是稍微复杂一点?
I'm using ASP.NET MVC 2 and have a login page that is secured via HTTPS. To ensure that the user always accesses those pages via SSL, I've added the attribute [RequireHttps]
to the controller. This does the job perfectly.
When they have successfully logged in, I'd like to redirect them back to HTTP version. However, there isn't a [RequireHttp]
attribute and I'm struggling to get my head around how I might achieve this.
The added (potential) complication is that the website when in production is hosted at the route of the domain, but for development and testing purposes it is within a sub directory / virtual directory / application.
Am I over-thinking this and is there an easy solution staring me in the face? Or is it a little more complex?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过一番挖掘后,我按照自己的思路进行了开发,因为似乎没有一个好的内置解决方案(如前所述,对于 MVC2 应用程序来说,有一个很好的解决方案,其形式为 [RequireHttps])。受到 çağdaş 的解决方案的启发 这个问题,我适应了以下代码:
我现在可以将其添加到我的控制器方法中,并且它的行为(看起来)符合预期。如果我从 HTTPS 协议重定向到控制器上的索引操作,它将重定向到 HTTP。它只允许对 Index ActionResult 进行 HTTP 访问。
After a bit of digging, I went along the lines of rolling my own as there didn't appear to be a good built-in solution to this (as mentioned, there is a great one for MVC2 applications in the form of [RequireHttps]). Inspired by çağdaş's solution to this problem and I adapated to come up with the following code:
I can now add this to my Controller methods and it behaves (seemingly) as expected. If I redirect to the Index action on my controller from a HTTPS protocol, it will redirect to HTTP. It only allows HTTP access to the Index ActionResult.