HttpContext.Current静态类访问 [英] HttpContext.Current accessed in static classes

查看:250
本文介绍了HttpContext.Current静态类访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能叫 HttpContext.Current 从静态类和方法内?

我要存储在每个用户的基础上的值,但希望能够访问它以静态方式

例如。将这项工作?

 公共静态类StaticClass
{    公共静态字符串的东西
    {
        {返回HttpContext.Current.Items [SomeItem]的ToString()。 }
    }}


解决方案

是的这就是一种方式,它是有帮助的,当然就调用它当前必须处理请求,使有用的线索。

Can I call HttpContext.Current from within a static class and Method?

I want to store a value on a per-user basis but want to be able to access it in a static manner.

e.g. Will this work?

public static class StaticClass
{

    public static string SomeThing
    {
        get { return HttpContext.Current.Items["SomeItem"].ToString(); }
    }

}

解决方案

Yes thats one way in which it is helpful, of course the thread on which it is called must currently be processing a request to make it useful.

这篇关于HttpContext.Current静态类访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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