0

I have a small query. I have a website with login, I am allowing the user to be logged in only once. I took help of StackoverFlow to achieve that. Refer this: stackoverflow link

Here's the brief about it: When a user logs in I am adding a value to a session variable and application variable. And when user tries to loggin in again I check the session as well as Application variables and if it does not exists then I am allowing user to login. This is working perfectly fine in chrome but gives some issues in Firefox and IE. In Chrome I could still get the saved session variable even if browser is closed and opened again. But in case of IE and firefox I cannot do that. My session variable goes blank when user closes the browser and opens again.

How do I save my session variables even after user closes the browser? Does it have something to do with sessionState?

Community
  • 1
  • 1
Arti
  • 2,993
  • 11
  • 68
  • 121
  • 2
    Chrome has a "continue where you left off" restart option that can preserve the session cookie; you should not rely on this. – Alex K. Jul 29 '15 at 10:57
  • Thanks all for quick reply. So if I cannot rely on that then are ther any asp.net variables which can persist its value even when browser is closed? – Arti Jul 29 '15 at 12:08
  • *Forms Authentication* uses a persistent cookie – Alex K. Jul 29 '15 at 15:30
  • Could please provide links on how to use Forms Authentication.. I have never used it before – Arti Jul 30 '15 at 07:39

1 Answers1

0

This is working perfectly fine in chrome but gives some issues in Firefox and IE.

That is because Chrome preserves session information. This feature isn't added to other browsers I am aware of. Since this feature isn't a documented standard, you can't rely on that.

Instead, you should set a cookie which contains a token and an expiration date. That cookie can be read when trying to log in the user.

The post How can I manually create a authentication cookie instead of the default method? can be useful to you since you use ASP.NET.

Community
  • 1
  • 1
Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325