asp.net - 带有滑动过期的 ASP.Net 外部 Cookie 显示为会话 cookie
问题描述
我正在尝试在 Asp.Net 中配置一个滑动过期 cookie。我希望 cookie 出现在 Google Chrome 开发人员工具 cookie 管理器中,并在身份验证后 5 分钟到期,但它显示为“会话”,并且在单击退出按钮之前永不过期。如果浏览器关闭,它确实会消失。
以下是目前的代码。该网站使用基于 Saml 的单点登录身份验证和Kentor.AuthServices
nuget 包(现在称为SustainSys.Saml2
,我们落后于版本)。
app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/signin"),
CookieSecure = CookieSecureOption.SameAsRequest,
ExpireTimeSpan = TimeSpan.FromMinutes(5),
SlidingExpiration = true,
Provider = new CookieAuthenticationProvider
{
OnApplyRedirect = ctx => { },
OnResponseSignIn = context =>
{
context.Properties.AllowRefresh = true;
context.Properties.ExpiresUtc = DateTimeOffset.UtcNow.AddMinutes(5);
}
}
});
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
Kentor.AuthServices.Configuration.Options.GlobalEnableSha256XmlSignatures();
OnResponseSignIn
最近根据此 MSDN 答案添加了
该块: https ://forums.asp.net/t/2121970.aspx?OWIN+Authentication+ExpireTimeSpan+not+working
我希望 cookie 在 30 分钟的非活动时间内过期。上面的代码设置为 5 以便于测试。
解决方案
推荐阅读
- javascript - 边距在 Safari 中不起作用:绝对 div
- typescript - 我有一个 Typescript NPM 模块,如何防止用户从错误的路径自动导入?
- python - 标头信息与数组不匹配。删除字符参数
- python - 如何使用 SQL Server 外部脚本的输出变量?
- networking - 如何从 OpenStreetMap 中提取街道图或网络?
- angular - Angular项目在同一个项目下指定多个主机名
- c++ - x86 处理器可以调用多少个子程序?
- javascript - 为什么查询选择器单击 div 但未触发任何操作?
- android - 有什么方法可以在 API Response 中获取 ArrayBuffer 吗?
- python - Django如何创建一个填充的更新对象表单?