response.cookies("name1").Expires="2003-7-16"  '该cookie的有效期限截至2003年7月16日

解决方案 »

  1.   

    ' Create user id and password cookies
        ' set their values and add to the collection
        Dim cookie As HttpCookie = New HttpCookie("UID")
        cookie.Value = "myid"
        cookie.Expires = #9/28/2002#
        Response.Cookies.Add(cookie)
        cookie = New HttpCookie("PASS")
        cookie.Value = "mypass"
        cookie.Expires = #9/28/2002#
     Response.Cookies.Add(cookie)You can read cookies using the Request.Cookies property. The code listed in Listing 2 reeds the cookies from the browser and adds them to a ListBox control.Listing 2. Reading cookies ' Read cookies
    Dim cookieCols As New HttpCookieCollection()
    cookieCols = Request.Cookies
    Dim str As String
    ' Read and add all cookies to the list box
    For Each str In cookieCols
       ListBox1.Items.Add("Cookie: " + str)
       ListBox1.Items.Add("Value:" & _
         Request.Cookies(str).Value)
    Next You can use the Remove and Clear methods of HttpCookieCollection  to remove a particular cookie by name or all cookies respectively. The code listed in Listing 3 delete the cookies using the Remove method.Listing 3. Deleting cookies Dim cookieCols As New HttpCookieCollection()
    cookieCols = Request.Cookies
    Dim str As String
    ' Read and add all cookies to the list box
    Request.Cookies.Remove("PASS")
    Request.Cookies.Remove("UID")A cookie can also store multiple values. This type of cookies called cookie dictionaries. You use Values property to create and read this type of cookies. The code listed in Listing 4 creates a dictionary cookie.Listing 4. Creating a dictionary cookieDim cookDict As HttpCookie = New HttpCookie("dict")
    cookDict.Values("fname") = "first name"
    cookDict.Values("lname") = "last name"
    cookDict.Values("Address") = "address"
    Response.Cookies.Add(cookDict)
      

  2.   

    用一个结构(枚举)或者类保存你需要的那些参数,设置过期时间长一点就行了。
    Response.Cookies("结构名").Expires="yyyy-MM-dd"
      

  3.   

    DateTime dt=new DateTime(2002,28,9);
    HttpCookie  cookie = New HttpCookie("UID")
        cookie.Value = "myname"
        cookie.Expires = dt;
    /////////////////////
    判断用户是否登陆,最好用Session来判断