使用 RedirectToAction 时如何设置协议?
我的目标操作需要 https。我已经有一个过滤器,如果请求通过 http 传入,它会重定向到 https,但我更愿意从一开始就通过 https 发送请求。
编辑
Darin 给出了一个答案(现在更新为其他内容),他问我为什么我通过 http 调用这第一个操作。他的观点很好,我刚刚更新了几个链接。这是解决我的问题的最简单、最安全的方法。
一旦我找到时间来评估 çağdaş 答案,我将使用它作为正确答案,因为我想这对其他一些人感兴趣(......包括将来的我)
The action I target needs https. I already have a filter in place that redirects to https if a request comes in via http, but I would prefer to send the request via https right from the start.
EDIT
There was an answer from Darin (updated now to something else ) where he asked why I call this first action by http anyway. He had a good point there and I just updated a couple of links. This was the easiest and securest way to fix my problem.
Once I find the time to evaluate çağdaş answer I will use this as the correct answer, because I guess thats of interest for some other people (...including me in the future)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道您是否必须使用
RedirectToAction
但使用UrlHelper
和控制器的Redirect
方法您可以执行以下操作:I don't know if you must use
RedirectToAction
but with aUrlHelper
and the controller'sRedirect
method you can do this :ASP.NET MVC 3 包括 RequireHttpsAttribute 这可能会有所帮助。
ASP.NET MVC 3 includes the RequireHttpsAttribute which may be of assistance.