小第初学Cookies,请高手指教几点cookies的用法。

解决方案 »

  1.   

    读取 Cookie (Visual C#)请参见
    代码:编写 Cookie (Visual C#) | HttpCookie 类 | Web 应用程序示例主题下面示例使用 HttpCookie 类及其属性读取具有特定名称的 Cookie。
    示例
    HttpCookie myCookie = new HttpCookie("MyTestCookie");
    myCookie = Request.Cookies["MyTestCookie"];// Read the cookie information and display it.
    if (myCookie != null)
       Response.Write("<p>"+ myCookie.Name + "<p>"+ myCookie.Value);
    else
       Response.Write("not found");
      

  2.   

    下面的示例将使用 HttpCookie 类及其属性编写一个一分钟后将失效的 Cookie。
    示例
    HttpCookie myCookie = new HttpCookie("MyTestCookie");
    DateTime now = DateTime.Now;// Set the cookie value.
    myCookie.Value = now.ToString();
    // Set the cookie expiration date.
    myCookie.Expires = now.AddMinutes(1);// Add the cookie.
    Response.Cookies.Add(myCookie);Response.Write("<p> The cookie has been written.");