Service stack: Difference between GetSession and SessionAs<t>

早过忘川 提交于 2019-12-12 21:25:41

问题


Are there any significant differences between Service.GetSession() and Service.SessionAs<T>() and how they resolve the sessions?

I'm maintaining this code that makes use of one in some requests and uses the later in others. Are there interchangeable or are their some other considerations?


回答1:


Exactly this difference

public virtual IAuthSession GetSession(bool reload = false)
{
    var req = this.Request;
    if (req.GetSessionId() == null)
        req.Response.CreateSessionIds(req);
    return req.GetSession(reload);
}

protected virtual TUserSession SessionAs<TUserSession>()
{
    var ret = TryResolve<TUserSession>();
    return !Equals(ret, default(TUserSession))
        ? ret 
        : Cache.SessionAs<TUserSession>(Request, Response);
}

I have never used any of them, but it seems that they should not be randomly interchanged. You can browse this source code here and figure out how significantly different they are. It's hard to tell at the first glance due to the lack of documentation



来源:https://stackoverflow.com/questions/20633428/service-stack-difference-between-getsession-and-sessionast

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!