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
bruce barker - 29 Oct 2007 17:24 GMT
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)
> 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
[quoted text clipped - 39 lines]
> End If
> End Sub
kelly.pearson@po.state.ct.us - 30 Oct 2007 12:46 GMT
Thank you, worked like a charm! I wasn't including the entire domain
name in the URL when I was calling the page.
> 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
[quoted text clipped - 53 lines]
>
> - Show quoted text -