我使用ASP.NET身份創建了一個新的ASP.NET MVC網站。我使用由Visual Studio 2017生成的標準邏輯,並且我選擇了個人用戶帳戶。增加登錄超時
一切工作正常,只是它似乎在約10至20分鐘的不活動狀態下注銷我,我想保持登錄更長的時間。
Googling around後,我發現有關設置CookieAuthenticationOptions.ExpireTimeSpan
的信息。但是,使用調試器,我可以看到這個值默認設置爲14天。
Startup.Auth.cs:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
},
//SlidingExpiration = true, // Default: true
//ExpireTimeSpan = TimeSpan.FromHours(1) // Default: 14 days
});
的Web.Config:
<system.web>
<authentication mode="None" />
<compilation debug="true" targetFramework="4.6" />
<httpRuntime targetFramework="4.5.2" executionTimeout="240" maxRequestLength="20480" />
<httpModules>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
</httpModules>
<customErrors mode="Off"></customErrors>
</system.web>
<system.webServer>
<modules>
<remove name="FormsAuthentication" />
<remove name="ApplicationInsightsWebTracking" />
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" />
</modules>
<validation validateIntegratedModeConfiguration="false" />
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="20971520" />
</requestFiltering>
</security>
</system.webServer>
所以,沒有人知道如何增加的時間量我得到註銷由於前不活動?
謝謝,但表單身份驗證是舊的方式,ASP.NET身份是新的方式。當然,唯一的答案不能是我必須以舊的方式做事。 –