Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There's a detailed <a href="http://msdn.microsoft.com/en-us/library/aa480476.aspx" rel="nofollow noreferrer">article on MSDN</a> that explains how Forms authentication works and what are the available configuration options. Basically Forms authentication uses cookies (unless you specifically tell it not to). So you could set the expiration date for your Forms authentication cookies to 24 hours. But there's a catch. You probably need to roll your own Membership code, since by default, the <code>timeout</code> attribute of the <code>forms</code> element is also used to set the lifetime of the persistent cookie. And you don't want that. You'd want to set the expiration for your cookie to 24 hours.</p> <p>The way it works is that after the user logs in, the Forms authentication cookie is created, and afterwards it's included along with each request until it expires. From the linked article: The Membership Provider has code similar to this when authenticating a user:</p> <pre><code>if (Membership.ValidateUser(userName.Text, password.Text)) { if (Request.QueryString["ReturnUrl"] != null) { FormsAuthentication.RedirectFromLoginPage(userName.Text, false); } else { FormsAuthentication.SetAuthCookie(userName.Text, false); } } else { Response.Write("Invalid UserID and Password"); } </code></pre> <p>You can create a Forms Authentication ticket using the <a href="http://msdn.microsoft.com/en-us/library/system.web.security.formsauthenticationticket.aspx" rel="nofollow noreferrer">FormsAuthenticationTicket</a> class:</p> <pre><code>FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, "cookieName", DateTime.Now, DateTime.Now.AddHours(24), // value of time out property false, String.Empty, FormsAuthentication.FormsCookiePath); </code></pre> <p>Forms authentication uses the Encrypt method for encrypting and signing the forms authentication ticket:</p> <pre><code>string encryptedTicket = FormsAuthentication.Encrypt(ticket); </code></pre> <p>Create the cookie:</p> <pre><code>HttpCookie authCookie = new HttpCookie( FormsAuthentication.FormsCookieName, encryptedTicket); </code></pre> <p>Add the cookie to the cookie collection:</p> <pre><code>Response.Cookies.Add(authCookie); </code></pre> <p>And that should be about it.</p> <p>You probably need to roll your own cookie, because by default, the <code>timeout</code> property that you specified for your <code>forms</code> is the one that's going to be used for the cookie timeout. So in your example:</p> <pre><code>&lt;authentication mode="Forms"&gt; &lt;forms loginUrl="Login.aspx" timeout="15" slidingExpiration="true"/&gt; &lt;/authentication&gt; </code></pre> <p>The cookie's timeout will be 15 minutes also. Probably the easier approach in your case would be to handle your enforced 24-hour timeout using a session variable. Since you'd only hit that if the user was actually active during that period (otherwise it would have timed-out from the cookie). So you could just terminate a Session if had been active for over 24 hours.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload