【问题标题】:Retrieve an ASP.NET cookie without the [key]= part检索没有 [key]= 部分的 ASP.NET cookie
【发布时间】:2015-01-02 18:27:20
【问题描述】:

我有一个这样设置的 ASP.NET cookie:

string identifier = Guid.NewGuid().ToString();
HttpCookie dateCookie = new HttpCookie("identifier");
dateCookie.Values.Add("identifier", identifier);
dateCookie.Expires = DateTime.Now.AddHours(12);
Response.Cookies.Add(dateCookie);

然后我像这样检索它:

string cookievalue = Request.Cookies["identifier"].Value;

cookievalue 现在有这个值:

identifier=79976995-468a-4ff0-b259-9686c487f9d5

我如何检索 cookie 以便我只得到:

79976995-468a-4ff0-b259-9686c487f9d5

【问题讨论】:

  • 使用Split方法。Split('=')[1]会给你79976995-468a-4ff0-b259-9686c487f9d5

标签: c# asp.net cookies


【解决方案1】:
string strcookie=cookievalue.Split('=')[1];

Split MSDN

希望你能理解并且它对你有用。

【讨论】:

    猜你喜欢
    • 2019-03-12
    • 2014-11-15
    • 2022-10-30
    • 2015-11-02
    • 1970-01-01
    • 2014-10-27
    • 2011-02-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多