Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / October 2007

Tip: Looking for answers? Try searching our database.

cookie.domain bug??

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
kelly.pearson@po.state.ct.us - 29 Oct 2007 17:09 GMT
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 -

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.