【问题标题】:Not updating cookie values不更新 cookie 值
【发布时间】:2014-01-24 00:19:52
【问题描述】:

在我的项目中,我编写了用于创建 cookie 的代码。

我需要在另一个页面上检索它的值。这是我在 Login.aspx 按钮单击事件上尝试过的:

Guid guid_string_Id = System.Guid.NewGuid();
 string newID = guid_string_Id.ToString();

Response.Cookies["name"]["Font"] = newID;
Response.Redirect("page2.aspx");

在 page2.aspx 的页面加载时,

if (Request.Cookies["name"] != null)
{
  string new_ID;
  if (Request.Cookies["name"]["Font"] != null)
  {
    new_ID = Request.Cookies["name"]["Font"]; 
  }
}
else
{
  Response.Redirect("Login.aspx");
}

我总是发现 cookie 值保持不变。会是什么问题?

在我的 web.config 中,我设置了:

<sessionState mode="InProc"  regenerateExpiredSessionId="true" stateNetworkTimeout="30" sqlCommandTimeout="30" cookieless="false" timeout="30">
</sessionState>

【问题讨论】:

    标签: c# asp.net cookies


    【解决方案1】:

    在您的 Login.aspx 页面上,您只需将 cookie 添加到 cookie 集合中:

    Guid guid_string_Id = System.Guid.NewGuid();
    string newID = guid_string_Id.ToString();
    
    var cookie = new HttpCookie("font", newID);
    Response.Cookies.Add(cookie);
    Response.Redirect("page2.aspx");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-20
      • 2011-12-30
      • 2021-04-25
      • 1970-01-01
      相关资源
      最近更新 更多