【问题标题】:How to fix "Cookie not Sent Over SSL (4720)" ASP.NET MVC?如何修复“Cookie 未通过 SSL (4720) 发送”ASP.NET MVC?
【发布时间】:2018-01-23 10:11:08
【问题描述】:

1.Tester 测试我的 ASP.NET MVC 网站并报告“Cookie not Sent Over SSL(4720)”问题。

2.他们让我通过在 Web.config 中添加 <httpCookies httpOnlyCookies="true" requireSSL="true" /> 来解决这个问题,然后我按照说明进行操作。

3.当我运行和测试我的网站时的问题,当更改页面时,Session 和 TempData 为空。下面的代码显示了我如何设置 Session 和 TempData。

3.1 当用户转到“主页/索引”时,我设置了 Session 和 TempData。

public class HomeController : Controller
{
   public ActionResult Index()
   {
      TempData["class"] = "A";
      TempData.Keep();

      Session["status"] = "NO";

      return View();
   }
}

3.2 当用户将页面更改为“Admin/User”时,我得到 TempData["class"] 和 Session["status"] 但两者均为空。

public class AdminController : Controller
{
   public ActionResult User()
   {
      string userclass = TempData["class"] != null ? TempData["class"].ToString() : "";

      string userstatus = Session["status"] != null ? Session["status"].ToSring() : "";

      UserModel usermodel = new UserModel(userclass, userstatus);
      return View(usermodel);
   }
}
  1. 如果我从 Web.config 中删除 <httpCookies httpOnlyCookies="true" requireSSL="true" /> 并再次测试它就可以了。但是当测试人员测试这个网站时,仍然会出现“Cookie not Sent Over SSL (4720)”。

如何解决这个问题?

附:抱歉英语不好。

【问题讨论】:

  • 您是否在 IIS Express 中使用 SSL?
  • @Oscar 我通过从 Visual Studio 2013 运行它使用 iis express 来测试我的网站。
  • 但是您使用的是 SSL,是还是不是?如果您将 cookie 配置为通过 SSL 发送,但没有可用的 SSL,那么就是您的问题。
  • 我不了解 SSL,我在将网站发布到 iis 后进行代码和测试。然后测试人员测试网络安全并向我报告问题。

标签: asp.net-mvc session web-config httpcookie tempdata


【解决方案1】:

如果您将 cookie 设置为通过 SSL 安全发送,那么您必须在 IIS Express 中启用 SSL 才能使其正常工作。 当您为 Web 主机选择 SSL 选项时,Visual Studio 会配置所有必要的东西(例如您的服务器证书和设置)。

您会在 here 找到有关它的完整教程。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-18
    • 1970-01-01
    • 2016-07-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多