Cookie isn't being read

D

Doogie

Hi,
I am having a problem reading a cookie that I can see is being
created. I create the cookie in my global.aspx.vb page like so:

Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
Dim user As String = Current.User.Identity.Name
Dim roleCookieName As String = user & "-Roles"
Dim rolesList As String = Response.Cookies(roleCookieName ).Value

'Only try to create the cookie if it is not already created.
If (rolesList Is Nothing) Then
Dim rolesArray As String() = Common.GetRoles()
If (Not (rolesArray Is Nothing)) Then
rolesList = rolesList.Join(",", rolesArray)
Response.Cookies(roleCookieName ).Value = rolesList
Response.Cookies(roleCookieName ).Expires =
DateTime.Now.AddHours(2)
Else
Throw New HttpException("An error occurred determining
what roles exist for user: " & user)
End If
End If
End Sub

I then use this in the page load method of my page and within that
page load, I can retrieve this cookie just fine like so:

Dim userId as string = User.Identity.Name()
Dim roleCookieName As String = userId & "-Roles"
Dim roles As String = Response.Cookies(roleCookieName ).Value

The problem is that every 30 minutes we do a refresh of this page. So
when it does that, it goes back up to the Session_Start method above,
and tries to read the cookie. For some reason, it is returning
Nothing when it tries to read that cookie, even though I have gone out
and looked and the cookie exists. All my information that I write to
this cookie is not accessible in my GetRoles method the second time
around because it relies on session information that I lose after 30
minutes (thus why we are trying to write to a cookie).

Is there some reason, it can read the cookie the first time but cannot
read the cookie upon a refresh?
 
D

Doogie

Never mind, I believe the issue was that I was using Response to try
and read it instead of Request.
 

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

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top