会话到期值开始正常,然后更改为默认值 [英] Session expiry value starts off ok, then changes to default

查看:38
本文介绍了会话到期值开始正常,然后更改为默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试将会话设置为在 30 分钟后过期时,我遇到了一个特殊情况.我保存会话的代码如下所示.当我在这里设置断点时,变量的值就是我想要的(30 分钟).当我跨过 SaveSession 行时,缓存中的行的 ExpiryDate 为 30 分钟.但是,有些事情正在将缓存中的 ExpiryDate 更改回默认的 2 周,我不确定这可能是什么.这一行是我整个服务中唯一的 .SaveSession.

I have a special case when I'm trying to set my session to expire in 30 minutes. My code that saves the session looks like below. When I set a breakpoint here, the value of the variable is what I want (30min). When I step over the SaveSession line, the row in my cache has an ExpiryDate of 30 minutes away. However, something is changing the ExpiryDate in the cache back to the default of 2 weeks and I'm not sure what that could be. This line is the only .SaveSession in my entire service.

sessionExpiry = sessionExpiry ?? ServiceStack.SessionFeature.DefaultSessionExpiry;
authService.SaveSession(session, sessionExpiry);

推荐答案

您可以覆盖 AppHost.OnSaveSession() 以在每次保存用户会话时进行处理,例如:

You can override AppHost.OnSaveSession() to handle everytime the Users Session is saved, e.g:

public override void OnSaveSession(IRequest req, IAuthSession session, TimeSpan? expiresIn=null)
{
    return base.OnSaveSession(req, session, TimeSpan.FromMinutes(30));
}

这篇关于会话到期值开始正常,然后更改为默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆