且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

服务堆栈:GetSession 和 SessionAs 之间的区别

更新时间:2023-11-28 11:42:34

正是这个区别

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