cs0815
cs0815

Reputation: 17418

forms authentication - no logout

Usually I have:

<authentication mode="Forms">
<forms loginUrl="Login.aspx"
   timeout="30"
   slidingExpiration="true"
</authentication>

which (IMHO) means that the cookie expires after 30 minutes of inactivity - sliding expiration means that any activity sets the cookie's expiry time back to 30 minutes.

Now I have the requirement that I would like the cookie to be stored indefinately, unless the user logs out explicitly. This means, that even if the browser is closed and reopened and the user goes to a side that requires authentication, no login is required. Is this possible?

Upvotes: 0

Views: 168

Answers (2)

Daniel Liuzzi
Daniel Liuzzi

Reputation: 17167

What you describe sounds equivalent to forcing the remember me checkbox to always be checked. To achieve that, go to your your Login action, and do the following:

FormsAuthentication.SetAuthCookie(username, true);

Upvotes: 1

Ravi Gadag
Ravi Gadag

Reputation: 15881

use SetAuthCookie method. SetAuthCookie

FormsAuthentication.SetAuthCookie(UserID, false); // not persisting cookie accross the browser session.

FormsAuthentication.SignOut().// for signout

Upvotes: 0

Related Questions