您是否使用任何形式的認證/授權?如果是這樣,重定向到登錄屏幕應該是這裏的線索。您的Cookie可能會在X天后過期。如果使用ASPNET身份檢查Startup.cs
>>Startup.ConfigureAuth(IAppBuilder app)
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))
}
});
由於您使用窗體身份驗證正確的地方,檢查這個超時值將是你的網絡配置。你應該看到像這樣在配置只要你的Cookie是自動生成的
<!--
forms Attributes:
name="[cookie name]" - Sets the name of the cookie used for Forms
Authentication.
loginUrl="[url]" - Sets the URL to redirect client to for authentication.
protection="[All|None|Encryption|Validation]" - Sets the protection mode for
data in cookie.
timeout="[minutes]" - Sets the duration of time for cookie to be valid
(reset on each request).
path="/" - Sets the path for the cookie.
requireSSL="[true|false]" - Should the forms authentication cookie be sent
only over SSL?
slidingExpiration="[true|false]" - Should the forms authentication cookie
and ticket be reissued if they are about to expire?
-->
如果手動生成的Cookie,然後你只需要更新您的FormsAuthenticationTicket
類有正確的超時值。另外請注意,如果您在.config文件中有Cookie設置值,但是在代碼中手動生成工單/ cookie,則手動生成將覆蓋配置值。
請參閱此MSDN類規範在代碼中設置超時:https://msdn.microsoft.com/en-us/library/system.web.security.formsauthenticationticket.aspx
而且,如果cookie不是問題,你可能要檢查你的會話狀態在web.config中也是如此。請這傢伙在這裏..很簡單:https://msdn.microsoft.com/en-us/library/h6bb9cz9(v=vs.71).aspx
是應用程序池回收?您的安全Cookie是否過期? –
應用程序池正在回收。間隔設置爲1740分鐘,即29小時。有時這個頁面有時不會被重定向到登錄頁面,只要5天。我不確定安全Cookie是否過期。 @SteveGreene – npineda