2014-10-20 38 views
0

我想通過管理後端爲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... 
} 

回答

-1

從代碼擴展超時,此時你需要它

此外,如果你會嘗試在配置會導致應用程序池重啓更改此參數。

Session.Timeout = 40;

+0

ASP.NET身份不使用web.config來管理會話超時。我需要在數據庫中保持會話超時,並隨時將其全部應用於整個應用程序。 – 2014-10-20 13:16:01