【发布时间】:2011-07-23 18:21:21
【问题描述】:
我已经阅读了许多关于 ASP.NET MVC [RequireHttps] 的问题 - 但找不到这个问题的答案:
如果不是以https开头,如何使[RequireHttps]属性将url切换为https?
我有这个代码:
public ActionResult DoSomething()
{
return View("AnotherAction");
}
[RequireHttps]
public ActionResult AnotherAction()
{
return View();
}
但我收到一条错误消息:“请求的资源只能通过 SSL 访问。”
MVC 期货项目有一个类似的属性[RequireSsl(Redirect = true)]。但是现在已经过时了...... MVC 2 中的等价物是什么?
当有人输入 URL http://example.com/home/dosomething 或 URL http://example.com/home/anotheraction 时,我需要将他们自动重定向到 URL https://example.com/home/anotheraction
编辑这是事件的顺序:
从另一个网站调用 URL http://example.com/home/dosomething。他们将用户重定向到这个 url(使用 response.redirect 或类似的)。
DoSomething() 然后尝试返回AnotherAction(),但失败并显示错误消息“请求的资源只能通过 SSL 访问。”
【问题讨论】:
-
你可以编写一个自定义属性来做到这一点。
标签: c# asp.net-mvc-2 ssl requirehttps