【问题标题】:forms timeout issue in asp.net mvc在 asp.net mvc 中形成超时问题
【发布时间】:2017-03-03 23:53:27
【问题描述】:

如何在 asp.net mvc 中关闭表单身份验证。我有注册、登录和忘记密码页面,旨在进入 web 应用程序。 最初我

我目前将我的 asp.net mvc Web 应用程序托管为单个代码库和多个数据库格式。我面临在某个时间段过期的表单,并且 logon.aspx 页面出现在主页的中间。我发现这是因为以下代码:

webconfig:
<authentication mode="Forms"><forms timeout="180000" slidingExpiration="false"/></authentication>

logon.cshtml:
  FormsAuthentication.SetAuthCookie(user.UserName, false);
 return RedirectToAction("Index", "Home");

我不希望我的用户会话或表单在他们注销之前过期。如何删除身份验证模式或如何解决此超时问题? 请帮忙。

这是我的完整 webconfig 代码:

<system.web>
    <customErrors mode="Off" />
    <globalization uiCulture="en-AU" culture="en-AU" />
    <!--<sessionState mode="InProc" />-->
    <sessionState timeout="1500"></sessionState>
    <httpRuntime encoderType="AntiXssEncoder, OnlineAB" />
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </assemblies>
    </compilation>
    <authentication mode="Forms">
      <forms timeout="180000" slidingExpiration="false"/>

    </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>-->
    <pages>
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
      </namespaces>
    </pages>
  </system.web>

【问题讨论】:

    标签: c# asp.net-mvc timeout forms-authentication


    【解决方案1】:

    根据MSDN

    如果发出请求并且超过一半的超时间隔已经过去,则滑动到期会重置有效身份验证 cookie 的到期时间。如果 cookie 过期,用户必须重新认证。将 SlidingExpiration 属性设置为 false 可以通过根据配置的超时值限制身份验证 cookie 的有效时间来提高应用程序的安全性。

    从配置中移除这个属性

    <authentication mode="Forms">
      <forms timeout="180000" slidingExpiration="false"/>
    </authentication>
    

    并替换为:

    <authentication mode="Forms" />
    

    还增加会话超时或默认删除:

    删除这个:

    <sessionState timeout="1500"></sessionState>
    

    【讨论】:

    • 感谢 Zaheer Ahmed 的回复 :) 当我删除它时,在我在线托管应用程序后,我无法登录主页,它会打开另一个弹出窗口,上面写着“需要身份验证”。
    • 我也试过这个,一段时间后它不会停止重定向到 logon.aspx :(
    • 尝试删除会话超时你定义的时间很短
    • 我删除了。 :) 我现在正在检查应用程序。我的理解是 1500 是 25 小时,表示超时的会话持续时间。
    • 不是sessionStatetimeout的单位分钟吗?我觉得 1500 你想建议 25 分钟(我假设肯定不是 1500 分钟)。
    【解决方案2】:

    我知道这个问题很老,但我通过在 web.config 中添加机器密钥来解决它

    您可以为您使用的 .NET 版本生成一个机器密钥,并将其添加到 web.config 中的身份验证部分之后,如所附图像。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-24
      • 2015-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多