asp.net-mvc - 强制使用 HTTP 而不是 HTTPS

标签 asp.net-mvc ssl iis-7.5

我有一个用 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/

相关文章:

json - 我如何在 mvc 中返回 json 对象

asp.net-mvc - 使用 AJAX 绑定(bind)时创建/更新后具有 IEnumerable 属性的 Kendo Grid 模型未正确更新

ssl - iOS9 NSAppTransportSecurity 相对于 https 流量的实际含义是什么?

wordpress - 带有嵌套 WordPress 博客的 ELB 后面的 EC2 上的 SSL 问题

c# - .net 移动文件失去原始和父文件夹安全权限

ASP.Net MVC Controller 在部署到 IIS 7 时导致“未找到”错误

c# - mvc 将文件保存到站点中的文件夹

php - SSL - 将所有 Assets 指向 https

configuration - 无法读取配置文件,因为它超过了最大文件大小

.net - GZip 压缩在 IIS 7.5 上不起作用