WebCookieManager Help

I have went through the very lacking documentation of the WebCookieManager and I can’t make heads or tails of how it is supposed to work. I have never used cookies before so I am unsure where to start.

What I am trying to do is simply create a cookie and set the username of my logged in user to the cookie with a timeout of 30 mins (1800000 ms if I remember right). Then web the main page is opened if the cookie exists and isn’t timedout, then show a different page instead of the login. Upon clicking the logout button remove the cookie.

Here is what I have tried and where:
App > Opening Event

If WebCookieManager.Count > 0 Then
  Session.LoggedIn = True
  Session.UserName = WebCookieManager.Value("user")
  Var main As New MainPage
  main.Show
End If

Login Page > Login Button

WebCookieManager.Set("user", 1800000, "URL.COM", "", False, SameSiteStrength As WebCookieManager.SameSiteStrengths = WebCookieManager.SameSiteStrengths.Off) = Session.UserName

Logout Button

UserName = ""
LoggedIn = False

WebCookieManager.Remove("user", "URL.COM", "")

CurrentPage.Close

ShowLoginPage

Help?

Without building any kind of sample project, off the top of my head I’d suggest moving the App.Opening code. The App.Opening event occurs once when the application itself is launched. Try moving that code to Session.Opening instead which occurs when a user connects and creates a new session.

2 Likes

You need to use Session.cookies, WebCookieManager Is the name of the class.

4 Likes