ServiceStack会话时间增加

时间:2018-09-25 12:56:15

标签: c#

如何增加会话时间。它会在10分钟后退出,但我需要将其延长2小时。

我的代码:

public override void OnAuthenticated(IServiceBase AuthService, IAuthSession Session, IOAuthTokens Tokens, Dictionary<string, string> AuthInfo) {
    try { 
        base.OnAuthenticated(AuthService, Session, Tokens, AuthInfo);

        //var Manager = new ArbProManager(false, 0, "ArbProService");
        //fwkArbProMobile.dbContext.EntityUserAccount User;

        string dbName = ConfigurationManager.AppSettings["MasterDatabase"];
        DAL.MobileUser usrContext = new DAL.MobileUser(dbName);
        Types.MobileUser User = usrContext.GetForEmail(Session.UserAuthName);

         // User = Manager.UserAccountInstance(Session.UserAuthName);
         Session.UserAuthId = User.Id.ToString();
         Session.DisplayName = User.EmailAddress;
         Session.Email = User.ClientDatabaseName;
         Session.Sequence = User.UserGuid.ToString();
         //var session = AuthService.GetSession();
         //AuthService.SaveSession(session, TimeSpan.FromDays(100));

         //AuthService.SaveSession(Session, SessionExpiry);
         //var sessionKey = SessionFeature.GetSessionKey(AuthService.GetSessionId());
         //redis.ExpireEntryIn(sessionKey, slidingExpiry); 
         //new CredentialsAuthProvider { SessionExpiry = TimeSpan.FromDays(10) };
         //AuthService.SaveSession(Session, SessionExpiry);
         Logger.InfoFormat("ArbProAuthProvider:UserId {0} logged in as {1}", Session.UserAuthId, Session.DisplayName);
     }
     catch (Exception ex) {
         Logger.ErrorFormat("OnAuthenticated:Error='{0}'", ex.ToString());
         throw ex;
     }
 }

1 个答案:

答案 0 :(得分:0)

在ServiceStack中控制Session生存期的最灵活的方法是,每次保存会话时都进行拦截,并通过覆盖OnSaveSession中的AppHost来更改其保存的会话过期时间:< / p>

public override void OnSaveSession(
    IRequest httpReq, IAuthSession session, TimeSpan? expiresIn = null)
{
    var customExpiry = ...
    base.OnSaveSession(httpReq, session, customExpiry);
}