如何在serveride asp.net代码中读取从客户端javascript创建的cookie

时间:2012-06-01 09:24:26

标签: javascript asp.net

例如我在页面加载时放了一个cookie,在服务器端的按钮提交上有一些特定的值c#代码我如何获得该cookie的值?(asp.net)

2 个答案:

答案 0 :(得分:0)

以下是如何在C#中读取cookie:

string cookieValue = string.Empty;

if (Request.Cookies["cookiename"] != null)
{
    cookieValue = Request.Cookies["cookiename"].Value.ToString();
}

答案 1 :(得分:-2)

阅读Cookie:

if (Request.Cookies["NameofCookie"] != null)
{
    string value = string.Empty;
    if (Request.Cookies["NameofCookie"]["yourkey"] != null)
    { value= Request.Cookies["NameofCookie"]["yourkey"]; }
}