469,610 Members | 1,729 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,610 developers. It's quick & easy.

cookie.domain bug??

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

Oct 29 '07 #1
2 2670
are you using the domain name when you access the page? if you set the
cookie domain to .mydomain.com then the url must have that suffix as the
server name in the url.

http://foo.mydomain.com/somepage.aspx

or for security the browser will not save, nor will it send to a site
that doesn't match.

-- bruce (sqlwork.com)

ke***********@po.state.ct.us wrote:
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
Oct 29 '07 #2
Thank you, worked like a charm! I wasn't including the entire domain
name in the URL when I was calling the page.

On Oct 29, 12:24 pm, bruce barker <nos...@nospam.comwrote:
are you using the domain name when you access the page? if you set the
cookie domain to .mydomain.com then the url must have that suffix as the
server name in the url.

http://foo.mydomain.com/somepage.aspx

or for security the browser will not save, nor will it send to a site
that doesn't match.

-- bruce (sqlwork.com)

kelly.pear...@po.state.ct.us wrote:
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- Hide quoted text -

- Show quoted text -

Oct 30 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by | last post: by
4 posts views Thread by socialism001 | last post: by
17 posts views Thread by Bruno | last post: by
6 posts views Thread by kelvlam | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.