【问题标题】:How to setup Session Timeout in any place of the Application如何在应用程序的任何位置设置会话超时
【发布时间】:2014-12-15 08:44:22
【问题描述】:

我想通过 ASP.NET 身份配置的管理员后端更改 Session TimeoutIAppBuilder

这个想法是摆脱 IIS 手动重置,只需在数据库中配置会话超时。

也就是说我们可以在ASP.NET MVC App的不同地方访问CookieAuthenticationOptions吗?

例如,我们可以在HomeController 中进行吗? 有办法吗?

STARTUP.AUTH.CS

public void ConfigureAuth(IAppBuilder app)
        {
            // It goes from Database
            var sessionTimeout = Convert.ToInt32(SysConfigView.GetSysConfig().SessionTimeout);

            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                ExpireTimeSpan = TimeSpan.FromMinutes(sessionTimeout),
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath = new PathString("/Account/Login"),
                CookieName = ".MyApp_Authentication",
                SlidingExpiration = true
            });

          // There is other code...
}

【问题讨论】:

    标签: c# .net asp.net-mvc-5 asp.net-identity session-timeout


    【解决方案1】:

    在需要的地方延长代码超时时间

    此外,如果您尝试在配置中更改此参数,则会导致应用程序池重新启动。

    Session.Timeout = 40;

    【讨论】:

    • ASP.NET Identity 没有使用 web.config 来管理会话超时。而且我需要在数据库中保留会话超时,并随时将其应用于全局的整个应用程序。
    猜你喜欢
    • 2021-12-28
    • 2011-02-26
    • 2021-12-28
    • 2011-02-23
    • 1970-01-01
    • 2020-01-03
    • 2014-11-22
    • 2010-11-15
    • 2016-01-29
    相关资源
    最近更新 更多