Timeout屬性可以設置爲525,600分鐘(1年)的值。默認值是20分鐘。另一方面,請注意,如果因爲會話超時而增加的用戶數量很大,則會出現性能問題,您的非活動會話將保留在Web服務器內存中,這可能會導致應用程序池回收,從而導致丟失所有會話爲所有用戶。
您可以在web.config中的會話超時,如下圖所示:
的web.config:
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" executionTimeout="1800" />
<sessionState mode="InProc" timeout="30" />
<!-- For LDAP -->
<httpCookies httpOnlyCookies="true" />
<authentication mode="Forms">
<!-- Note: I also remove this part and try with only "sessionState" -->
<forms name=".ADAuthCookie" loginUrl="~/Account/Login" timeout="1"
slidingExpiration="false" protection="All" />
</authentication>
</system.web>
在另一方面,如果您使用ASP.NET Identity
,您無需使用web.config
中的設置。就在這兩行添加到您的UseCookieAuthentication()
方法如下圖所示:
....,
SlidingExpiration = true,
ExpireTimeSpan = TimeSpan.FromMinutes(1)
...
因此,將如下圖所示的方法的最終代碼:
Startup.Auth.cs:
public void ConfigureAuth(IAppBuilder app)
{
// Code removed for brevity.
// Configure the sign in cookie
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
// Enables the application to validate the security stamp when the user logs in.
// This is a security feature which is used when you change a password or add an external login to your account.
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
},
SlidingExpiration = true,
ExpireTimeSpan = TimeSpan.FromMinutes(30) //Set the session timeout at here
});
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(1));
app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);
}
希望這有助於...
更新:
關於第二個問題,這個問題是關係到IIS
而非調度Quartz.NET
,Hangfire
,等等。另一方面,有很多解決的方法貼在網上,但只有一些人在工作。在我看來,沒有必要應用大量的配置設置。只需在您發佈應用程序並享受的服務器上安裝Keep Alive Service For IIS 6.0/7.5即可。然後,您發佈的應用將是以後應用程序池回收,IIS /應用重啓活着,等
我每天回收的應用程序池晚上7點到使用Windows身份驗證。 – JSK
請參閱上面的我的更新,並嘗試在發佈應用程序的IIS服務器上使用Keep Alive Service。 –
謝謝,穆拉特。答案並沒有真正回答我的問題,但也許對別人有用。 – JSK