3

我有一个 ASP.NET 4 站点。我在 web.Config 中的身份验证中将超时设置为 100 分钟,但是当用户突然使用站点时,即使 3 分钟后站点也会提示登录。下面的代码是我的 web.Config 文件

    <?xml version="1.0" encoding="utf-8"?>
    <!--
    For more information on how to configure your ASP.NET application, please visit
    http://go.microsoft.com/fwlink/?LinkId=169433
    -->
    <configuration>
    <appSettings>
    <add key="ImageMaxFileLengh" value="500" />
    </appSettings>
  <system.web>
    <pages enableViewStateMac="false"></pages>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral,   PublicKeyToken=b77a5c561934e089" />
        <add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
        <add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Speech, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      </assemblies>
    </compilation>
    <authentication mode="Forms">
      <forms defaultUrl="~/Default.aspx" loginUrl="~/Account/Login.aspx" timeout="100" name="HajLogin" slidingExpiration="true" />
    </authentication>
    <!--<membership>
      <providers>
        <clear />
        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
      </providers>
    </membership>
    <profile>
      <providers>
        <clear />
        <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
      </providers>
    </profile>
    <roleManager enabled="false">
      <providers>
        <clear />
        <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
        <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
      </providers>
    </roleManager>-->
    <httpHandlers>
      <add path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" verb="*" validate="false" />
    </httpHandlers>
  </system.web>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <validation validateIntegratedModeConfiguration="false" />
    <handlers>
      <add name="Telerik_Web_UI_WebResource_axd" verb="*" preCondition="integratedMode" path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" />
    </handlers>
  </system.webServer>
</configuration>
4

3 回答 3

6

确保您没有在代码中创建 FormsAuthenticationTicket。这将覆盖您在 web.config 中配置的超时值。如果您在代码中执行此类操作,则可能是它不起作用的原因:

FormsAuthenticationTicket ticket = new FormsAuthenticationTicket
(
   ...
   DateTime.Now, // issueDate
   DateTime.Now.AddMinutes(30), // expiration
   ...
 );

如果您没有执行上述操作,请查看您的 SessionTimeout。尝试增加它。

问候。

于 2012-10-30T18:07:37.910 回答
4

请不要将验证超时与会话超时混淆。

在寻求身份验证时,您将表单 1000 设置为超时。一旦它通过身份验证,您就不会查看此变量以使经过身份验证的会话到期。

以下是一些描述差异的好链接:

这是一个很好的链接,描述了在表单身份验证中设置会话超时:

于 2012-10-30T18:03:47.517 回答
0

Forms 标记中的 Timeout 属性指定当记住我复选框被选中时持久 cookie有效的分钟数。

于 2020-06-05T12:39:43.607 回答