【问题标题】:Can you configure OWIN Cookie Authentication to prevent certain URLs from affecting sliding expiration?是否可以配置 OWIN Cookie 身份验证以防止某些 URL 影响滑动过期?
【发布时间】:2015-06-05 05:05:07
【问题描述】:

我们有一个使用 OWIN Cookie 身份验证的 ASP.NET MVC 5 应用程序,具有滑动到期。在客户端,我们有一个脚本,它每分钟轮询 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")
});

感谢任何帮助!

【问题讨论】:

    标签: c# asp.net-mvc owin


    【解决方案1】:

    我没有对此进行测试,但理论上它应该可以工作:

    app.Use("/path1", app2 => app2.UseCookieAuthentication(...));
    app.Use("/path2", app3 => app3.UseCookieAuthentication(...));
    app.UseCookieAuthentication(...);
    

    Use 调用的顺序很重要。 Owin 的美妙之处在于它能够覆盖子路径上的任何行为。

    【讨论】:

    猜你喜欢
    • 2014-10-03
    • 2023-04-05
    • 2014-06-12
    • 1970-01-01
    • 2023-03-19
    • 2012-01-30
    • 2015-10-09
    • 2023-03-31
    • 2021-09-18
    相关资源
    最近更新 更多