【发布时间】:2019-04-04 18:02:02
【问题描述】:
我正在开发一个带有 Identity 的 ASP.NET Core 2.0 应用程序来管理用户连接。
我有一些自定义 Manager、Store 和 Providers 来满足我的应用程序的需要:
services.AddIdentity<Utilisateur, Profil>().AddUserManager<CustomUserManager<Utilisateur>>().AddRoleManager<CustomRoleManager>().AddDefaultTokenProviders();
services.AddTransient<IUserStore<Utilisateur>, UserStore>();
services.AddTransient<IRoleStore<Profil>, ProfileStore>();
services.AddTransient<IPermissionProvider, PermissionProvider>();
我已经为身份验证设置了应用程序 cookie:
app.UseAuthentication();
还有
services.ConfigureApplicationCookie(options =>
{
// Cookie settings
options.Cookie.HttpOnly = true;
options.ExpireTimeSpan = TimeSpan.FromMinutes(60);
// If the LoginPath isn't set, ASP.NET Core defaults the path to /Account/Login.
options.LoginPath = new PathString("/Connexion/Login");
options.LogoutPath = new PathString("/Connexion/SignedOut");
// If the AccessDeniedPath isn't set, ASP.NET Core defaults the path to /Account/AccessDenied.
options.AccessDeniedPath = new PathString("/Connexion/AccessDenied");
options.SlidingExpiration = true;
});
问题是用户在30分钟后自动断开连接,即使他没有空闲并且此时正在使用应用程序。
如何刷新或重新创建身份验证 cookie 以避免此问题?
我尝试创建一种方法来刷新 cookie,但它似乎效果不佳...即使这样,用户也会断开连接。
[HttpPost]
[RefreshLogin]
[RequiresPermission("Pages.Modification")]
public IActionResult SavePagesOrder()
{...}
以及方法:
public class RefreshLoginAttribute : Microsoft.AspNetCore.Mvc.Filters.ActionFilterAttribute
{
public override async Task OnActionExecutionAsync(Microsoft.AspNetCore.Mvc.Filters.ActionExecutingContext context, Microsoft.AspNetCore.Mvc.Filters.ActionExecutionDelegate next)
{
await context.HttpContext.RefreshLoginAsync();
await next();
}
}
您有解决我问题的想法吗?
【问题讨论】:
标签: c# asp.net-identity asp.net-core-2.0 session-cookies