是否有一种方式来获得从静态上下文中的Session对象? [英] Is there a way to get the Session object from a static context?

查看:69
本文介绍了是否有一种方式来获得从静态上下文中的Session对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#/ ASP.NET项目。我希望能够得到Session对象(HttpSessionState)从静态上下文上的手柄。有没有什么办法来做到这一点?

I'm in a C# / ASP.NET project. I'd like to be able to get a handle on the Session object (HttpSessionState) from a static context. Is there there any way to do so?

推荐答案

试试这个:

    private static new HttpSessionState Session
    {
        get { return HttpContext.Current.Session; }
    }

然后再从另一个静态功能,你可以称其为

then from another static function you can just refer to it as

var myObj = Session[myKey];

就像你从常规的非静态code会。

just like you would from your regular non-static code.

这篇关于是否有一种方式来获得从静态上下文中的Session对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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