R – Asp.net MVC authentication ticked without create auth cookie

asp.net-mvcforms-authentication

I'm authenticating a user in my application with the method "FormsAuthentication.SetAuthCookie" method, but when I close the browser and reopen it, it is still authenticated, but the session is over already, then my app crashes because it has necessary data on the session to generate the menus.

What I want to do is the following: Create an authentication ticket without create a auth cookie to, whenever the user open the page in a new browser session it will request the login once again.

How can I achieve this.

Best Answer

Sessions and authentication are different. If you want the cookie to go away when the browser closes then use

FormsAuthentication.SetAuthCookie("username", false);