在我的CookieAuthentication
的ExpireTimeSpan
中定义的一段时间不活动后,我想在我的登录重定向中打印一条消息,当注销发生时,是否有办法做到这一点?
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
ExpireTimeSpan = TimeSpan.FromMinutes(30),
SlidingExpiration = true,
LoginPath = new PathString("/signin"),
CookieName = ".Cookies",
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))
}
});
您可以这样指定自定义重定向:
public void ConfigureAuth(IAppBuilder app)
{
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
// [...]
Provider = new CookieAuthenticationProvider
{
// [...]
OnApplyRedirect = ApplyRedirect
}
});
app.Use<ClaimsLogger>();
}
private static void ApplyRedirect(CookieApplyRedirectContext context)
{
// custom redirect logic
var uri = context.RedirectUri;
context.Response.Redirect(uri);
}