我把源码给大家看一下,是一个共享类,然后看看怎么解决?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的过期时间。 但每次打开页面,按钮还是不可用,为什么?
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的过期时间。
但每次打开页面,按钮还是不可用,为什么?