如果没有设置Cookie的过期时间,是不是关闭浏览器之后cookie就失效呢?
那为什么我试过总是不行呢?是不是.net的缓存在作怪呢?
谁能给个例子呢?谢谢大家了!

解决方案 »

  1.   

    楼主说的是对的,不知你是怎么设置Cookie的?
      

  2.   

    我把源码给大家看一下,是一个共享类,然后看看怎么解决?Imports System.Web
    Public Class mycookie
        Private Shared _cookie As HttpCookie = HttpContext.Current.Request.Cookies("eb0768")
        Private Shared Sub ininCookie()
            _cookie = New HttpCookie("eb0768")
        End Sub
        Public Shared Property cookieItem(ByVal var_item As String) As String
            Get
                If _cookie Is Nothing Then
                    Return Nothing
                Else
                    Return _cookie.Values(var_item)
                End If
            End Get
            Set(ByVal Value As String)
                If _cookie Is Nothing Then
                    ininCookie()
                End If
                _cookie.Values(var_item) = Value
                HttpContext.Current.Response.Cookies.Add(_cookie)
            End Set
        End Property
    End Class
    下面是使用这个共享类,效果是点击按钮后,点击的按钮变得不可用!
        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            If Not mycookie.cookieItem("Voted") Is Nothing Then
                Response.Write(mycookie.cookieItem("Voted"))
                Button1.Enabled = False
            End If
        End Sub    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            mycookie.cookieItem("Voted") = True
            Response.Redirect("temp.aspx")
        End Sub按理说,下次再打开页面,cookie应该失效才对啊,因为我没有设置Cookir的过期时间。
    但每次打开页面,按钮还是不可用,为什么?
      

  3.   

    关注.我讨厌cookie老用不成功.web里面什么东西都麻烦.郁闷.
      

  4.   

    如果真的出楼主的问题,ASP.NET的安全性还值得考虑.