我有一个用 ASP.Net MVC4 编写并部署到 IIS7.5 的网站,用户首先需要登录才能浏览网站的其余部分,例如,源代码如下:
路线:
localhost/project/account/logon
localhost/project/apple
localhost/project/banana
登录方式:
[RequireHttps]
public ActionResult Logon(string returnUrl)
{
...
return View();
}
[HttpPost]
public ActionResult Logon(string user, string pwd, bool remember)
{
...
string url = "/apple";
return Redirect(url);
}
问题是,在用户登录后,我们使用 return Redirect('/apple')
将用户重定向到其他链接,它还使用 HTTPS https://localhost/project/apple
访问新链接。
如何防止重定向使用 HTTPS?
最佳答案
您可以使用以下内容:
[HttpPost]
public ActionResult Logon(string user, string pwd, bool remember)
{
var url = Url.Action("someAction", "someController", null, "http");
return Redirect(url);
}
但是不要那样做。切勿通过未加密的 channel 传输 session cookie。一旦用户通过身份验证并且您向他发送了一个身份验证 cookie,该用户在您的网站上所做的一切都应该通过 SSL 发送。我还建议您使用 secure
标志(web.config 中的 requireSSL="true"
)发出表单例份验证 cookie。
关于asp.net-mvc - 强制使用 HTTP 而不是 HTTPS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18052794/