K
kelly.pearson
Is this a bug? I am trying to write a cookie that can be accessed by
various .Net applications on our domain. However, whenever I add the
domain property to the cookie, no errors get thrown but the cookie
doesn't get written. I am trying this from my localhost using
vs2003, .net framework 1.1, windows xp prof. Sample code I am testing
with is below.
Public Class WebForm1
Inherits System.Web.UI.Page
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
' Get cookie from current request.
Dim cookie As HttpCookie
cookie = Request.Cookies.Get("DateCookieExample")
' Check if cookie exists in the current request
If (cookie Is Nothing) Then
' Create cookie.
cookie = New HttpCookie("DateCookieExample")
' Set value of cookie to current date time.
cookie.Value = "This is the cookie value"
' Set Domain for the cookie (limits scope of the
cookie)
cookie.Domain = ".CTDOL.STATE.CT.US"
'******* If the above line is active the cookie does NOT get written
out
'******* If the above line is commented out the cookie gets written
'******* What am I doing wrong??? It seemed simple.
' Set cookie to expire in 1 minutes.
cookie.Expires = DateTime.Now.AddMinutes(1).ToString
' Insert the cookie in the current HttpResponse.
Response.Cookies.Add(cookie)
Response.Write("Cookie Created")
Else
Response.Write("Cookie retrieved from client")
End If
End Sub
various .Net applications on our domain. However, whenever I add the
domain property to the cookie, no errors get thrown but the cookie
doesn't get written. I am trying this from my localhost using
vs2003, .net framework 1.1, windows xp prof. Sample code I am testing
with is below.
Public Class WebForm1
Inherits System.Web.UI.Page
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
' Get cookie from current request.
Dim cookie As HttpCookie
cookie = Request.Cookies.Get("DateCookieExample")
' Check if cookie exists in the current request
If (cookie Is Nothing) Then
' Create cookie.
cookie = New HttpCookie("DateCookieExample")
' Set value of cookie to current date time.
cookie.Value = "This is the cookie value"
' Set Domain for the cookie (limits scope of the
cookie)
cookie.Domain = ".CTDOL.STATE.CT.US"
'******* If the above line is active the cookie does NOT get written
out
'******* If the above line is commented out the cookie gets written
'******* What am I doing wrong??? It seemed simple.
' Set cookie to expire in 1 minutes.
cookie.Expires = DateTime.Now.AddMinutes(1).ToString
' Insert the cookie in the current HttpResponse.
Response.Cookies.Add(cookie)
Response.Write("Cookie Created")
Else
Response.Write("Cookie retrieved from client")
End If
End Sub