Joh*_*ann 7 c# asp.net-mvc owin
我们有一个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)
任何帮助表示赞赏!
我还没有测试过这个,但理论上它应该有效:
app.Use("/path1", app2 => app2.UseCookieAuthentication(...));
app.Use("/path2", app3 => app3.UseCookieAuthentication(...));
app.UseCookieAuthentication(...);
Run Code Online (Sandbox Code Playgroud)
调用的顺序Use
很重要。Owin 的美妙之处在于它能够覆盖子路径上的任何行为。
归档时间: |
|
查看次数: |
891 次 |
最近记录: |