【问题标题】:setting cookies using asp.net使用 asp.net 设置 cookie
【发布时间】:2015-07-05 03:10:41
【问题描述】:

我正在尝试使用 asp.net 网页 (Webmatrix) 设置 cookie,并且我已获得此 c# 代码来读取 cookie 并设置 cookie。我不确定如何应用它来设置 cookie。例如,我希望设置一个名为 islogged 的​​ cookie,并将其值设为 yes。

var cookieValue = Request.Cookies["myCookie"].Value;

任何帮助将不胜感激。

【问题讨论】:

    标签: asp.net cookies


    【解决方案1】:
    Response.Cookies.Add(new HttpCookie("islogged", "true"));
    

    【讨论】:

      【解决方案2】:

      在你的情况下:

      // Set the value in a response
      Response.Cookies["islogged"].Value = "true";
      
      // After a post back read the value from the request
      Request.Cookies["islogged"].Value;
      

      要了解更多信息,您可以查看documentation

      【讨论】:

      • 谢谢 - 这很有意义 - 比 MSDN 更容易理解。
      猜你喜欢
      • 2021-12-14
      • 2020-05-22
      • 1970-01-01
      • 2014-05-31
      • 2010-11-14
      • 1970-01-01
      • 2020-05-30
      • 2014-04-18
      • 2015-01-18
      相关资源
      最近更新 更多