小编Joh*_*ann的帖子

是否可以基于每个用户设置ASP.NET Owin安全cookie的ExpireTimeSpan?

我们有一个使用Owin cookie身份验证的ASP.NET MVC 5应用程序.目前,我们按如下方式设置cookie身份验证:

public partial class Startup
{
    public void ConfigureAuth(IAppBuilder app)
    {
        var timeoutInMinutes = int.Parse(ConfigurationManager.AppSettings["cookie.timeout-minutes"]);

        app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            AuthenticationMode = AuthenticationMode.Active,
            LoginPath = new PathString("/"),
            ExpireTimeSpan = TimeSpan.FromMinutes(timeoutInMinutes),
            SlidingExpiration = true,
            LogoutPath = new PathString("/Sessions/Logout")
        });
    }
}
Run Code Online (Sandbox Code Playgroud)

我们有一个功能请求,允许我们的应用程序管理员在其组织内自定义会话超时.但是,上面的配置代码在MVC应用程序级别执行,我们的应用程序是多租户.有没有人知道如何在每个用户的基础上设置用户会话的ExpireTimeSpan,无论是在身份验证期间还是在某处覆盖Owin管道事件?

提前致谢!

c# asp.net cookies asp.net-mvc owin

17
推荐指数
1
解决办法
6630
查看次数

您是否可以配置OWIN Cookie身份验证以防止某些URL影响滑动过期?

我们有一个ASP.NET MVC 5应用程序使用OWIN Cookie身份验证和滑动过期.在客户端上,我们有一个脚本,每分钟轮询一次Web服务以获取通知.我们希望阻止该Web服务调用导致身份验证令牌到期向前滑动.有没有办法做到这一点?

我正在考虑在OnValidateIdentity处理程序中实现我自己的自定义滑动到期方法,但在该方法中设置ExpiresUtc似乎并不会实际影响令牌的到期日期.

app.UseCookieAuthentication(new CookieAuthenticationOptions
{
    Provider = new CookieAuthenticationProvider
    {
        OnValidateIdentity = cookieValidateIdentityContext =>
        {
            cookieValidateIdentityContext.Properties.ExpiresUtc = DateTime.UtcNow.AddMinutes(-1);
            return Task.FromResult(0);
        }
    },

    AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
    AuthenticationMode = AuthenticationMode.Active,
    LoginPath = new PathString("/"),
    SlidingExpiration = false,
    LogoutPath = new PathString("/Sessions/Logout")
});
Run Code Online (Sandbox Code Playgroud)

任何帮助表示赞赏!

c# asp.net-mvc owin

7
推荐指数
1
解决办法
891
查看次数

标签 统计

asp.net-mvc ×2

c# ×2

owin ×2

asp.net ×1

cookies ×1