在ASP中动态更改会话超时。净MVC 5(复制)

时间:2021-03-08 03:26:47

This question already has an answer here:

这个问题已经有了答案:

Is there a way to change Session Timeout on fly in ASP.NET MVC 5 globally without restarting application?

是否有一种方法可以在ASP中动态更改会话超时。没有重新启动应用程序的netmvc 5 ?

I know we can do

我知道我们能做到

public void ConfigureAuth(IAppBuilder app)
        {            
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                ExpireTimeSpan = TimeSpan.FromMinutes(10),
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath = new PathString("/Account/Login"),
                CookieName = ".MyApp1_Authentication",
                SlidingExpiration = true
            });
}

But is there a way to do it in other places of the application? Thank you!

但是,在应用程序的其他地方有这样的方法吗?谢谢你!

1 个解决方案

#1


2  

Close to a duplicate question but to answer this specifically, you can do this

类似于重复的问题,但要特别回答这个问题,你可以这样做

  HttpContext.Current.Session.Timeout = 20;

#1


2  

Close to a duplicate question but to answer this specifically, you can do this

类似于重复的问题,但要特别回答这个问题,你可以这样做

  HttpContext.Current.Session.Timeout = 20;