Cookies not readable in Session Open

I’ve been having trouble with a web app that sets cookies to remember user credentials. It seemed like the cookie values weren’t being read. After some debugging and trying various things, I discovered that you can’t read a cookie value in the Session Open handler. No error, it just returns an empty string as if the cookie didn’t exist.

Not sure if this is a bug, or should be documented somewhere. Hopefully posting it here will help someone one day.

I’ve found that using cookies on a page or control works better than putting it directly in the session open.

To store the value of the cookie.
Session.cookies.set (“cookie_name”, “value_being_stored”, expiration date)

This gets the value of the cookie based on the name you’ve given it.
Session.cookies.value (“cookie_name”)

IMPORTANT: You have to put in an expiration date or the cookie will expire once the browser is closed.

Thanks for the extra clarification Jeff. You triggered something in the back of my brain about not referring to Session within the Session object. I found it in the documentation

To refer to the current Session from within the Session object, use Self instead of Session as the prefix, especially in the Open event because it may return Nil.

I verified (2019R31) you can read the cookie in Session Open using Self.Cookies.Value(“cookiename”)

1 Like