Crista23
Crista23

Reputation: 3243

Cookie seems to never exist

I am facing a weird issue regarding cookies: I am trying to set up a cookie with the user id the first time the user logs into the application, and next time, if the cookie exists, not require the user authentication again.

For this I am using the code below:

The weird thing is that my cookie seems not to exist and the user is prompted with the log in screen all the time. When I try to use debugging, it appears to me that the cookie is not null, but it's got an empty string value. What can I do about this?

Many thanks!

Upvotes: 0

Views: 56

Answers (1)

Darren Wainwright
Darren Wainwright

Reputation: 30747

Are you trying to GET the cookie in the same code that SETS the cookie? If so, the cookie won't exist. Cookie gets SET on the users browser when the page has been delivered.

Also, can you confirm UserID.ToString() isn't actually an empty string..?

To test properly, set the cookie on page A, then redirect to page B and GET the cookie here.

Upvotes: 1

Related Questions