【发布时间】:2015-02-01 13:54:55
【问题描述】:
我正在开发一个最近从自定义身份验证解决方案迁移到 ASP.NET Identity 的 Web 应用程序。在我们应用程序的某些部分中,执行的过程很长,可能需要长达一个小时才能运行。在正常情况下,我们希望用户在 30 分钟不活动后自动注销。但是,对于发生长进程的屏幕,我们希望扩大自动注销窗口,以便在进程完成之前它们不会被踢出。我目前正在努力解决如何使用 Identity 来实现这一点。我目前在我的 Startup.Auth.cs 文件中使用以下代码:
public partial class Startup
{
// For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301883
public void ConfigureAuth(IAppBuilder app)
{
// Configure the user manager and signin manager to use a single instance per request
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
// Enable the application to use a cookie to store information for the signed in user
// and to use a cookie to temporarily store information about a user logging in with a third party login provider
// Configure the sign in cookie
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Login.aspx"),
ExpireTimeSpan = TimeSpan.FromMinutes(30),
SlidingExpiration = true,
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity =
SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser, int>(
TimeSpan.FromMinutes(30),
(manager, user) => user.GenerateUserIdentityAsync(manager),
userIdentity => userIdentity.GetUserId<int>())
}
});
}
}
在调用ConfigureAuth 之后,我目前看不到任何修改ExpireTimeSpan 值的方法。我希望能够从 Web 表单页面更改 Page_Load 事件处理程序中的值。有人知道方法吗?
【问题讨论】:
-
是否可以选择只进行 ajax 调用?以便访问会话?
-
@alexo:这是一个有趣的选择。我不知道为什么我没有考虑到这一点。我想我会把它放在我的后兜里,以防我找不到更改身份验证过期时间跨度设置本身的方法。
-
问题是,如果你在一个地方改变它,它就会到处改变,据我所知,这有点全球化。所以你可能不希望其他页面发生这种情况
-
@alexo:这是一个全局设置,但可以在每次页面加载时更改。例如,我可以让母版页在每次页面加载时将 ExpireTimeSpan 设置为其默认值,然后允许该值在页面加载时被任何希望它不同的页面覆盖。
-
当您的意思是全局时,您是指会话级别的全局还是服务器级别的全局?因为如果它的服务器级别并且您在一个会话中为特定用户更改它,那么它也会为其他用户更改。据我所知,它在服务器级别是全局的,如果这是您想要的行为,那么这就是答案吗?
标签: c# asp.net owin asp.net-identity-2