設定Forms認證的cookie失效時間

來源:互聯網
上載者:User

永續性 Cookie 由所有使用同一個 Cookie 儲存的應用程式共用,而且使用者可以在用戶端應用程式中開啟文檔。建立的永續性 Cookie 具有 30 分鐘的預設逾時值。通過在 Web.config 檔案中的表單節點內添加或更新逾時參數,可以更改此值。例如:

<forms loginUrl="login.aspx" name=".ASPXFORMSAUTH" timeout="100" />

例:

<authentication mode="Forms">
     <forms loginUrl="~/Default.aspx"
               name=".MetaTagUser"
               defaultUrl="~/Review/Default.aspx"
               timeout="30"
               slidingExpiration="true" />
</authentication>

<membership defaultProvider="MetaTagSqlProvider" userIsOnlineTimeWindow="30">
            <providers>
                <remove name="AspNetSqlProvider" />
                <add name="MetaTagSqlProvider"
                         type="System.Web.Security.SqlMembershipProvider"
                         connectionStringName="DSN_MemberStore"
                         enablePasswordRetrieval="false"
                         enablePasswordReset="true"
                         requiresQuestionAndAnswer="false"
                         passwordFormat="Hashed"
                         minRequiredNonalphanumericCharacters="0"
                         minRequiredPasswordLength="5"
                         applicationName="/MetaTag" />
            </providers>
 </membership>

<roleManager enabled="true"
         cacheRolesInCookie="false"
         cookieName=".MetaTagRoles"
         cookieTimeout="30"
         cookieSlidingExpiration="true"
         cookieProtection="All"
         defaultProvider="MetaTagSqlRoleProvider"
         createPersistentCookie="false"
         maxCachedResults="25">
            <providers>
                <remove name="AspNetSqlRoleProvider"/>
                <add connectionStringName="DSN_MemberStore"
                          applicationName="/MetaTag"
                          name="MetaTagSqlRoleProvider"
                          type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
            </providers>
        </roleManager>

 

1. Specifies the amount of time, in integer minutes, after which the cookie expires. The default value is 30. If the SlidingExpiration attribute is true, the timeout attribute is a sliding value, expiring at the specified number of minutes after the time the last request was received. To prevent compromised performance, and to avoid multiple browser warnings for users that have cookie warnings turned on, the cookie is updated when more than half the specified time has elapsed. This might result in a loss of precision. Persistent cookies do not time out.

2. The UserIsOnlineTimeWindow property value is checked during the call to GetNumberOfUsersOnline. If the LastActivityDate for a user is greater than the current date and time minus the UserIsOnlineTimeWindow value in minutes, then the user is considered online. You can determine whether a membership user is considered online with the IsOnline property of the MembershipUser class.

3. The CookieTimeout property is used when the CookieSlidingExpiration property is true and specifies the time-to-live in minutes for the roles cookie. To set the CookieTimeout value, add the cookieTimeout attribute to the roleManager element in the Web.config file for the ASP.NET application and specify an integer value.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.