cookie.domain bug??

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
 
B

bruce barker

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)
 
K

kelly.pearson

Thank you, worked like a charm! I wasn't including the entire domain
name in the URL when I was calling the page.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top