HttpContext.Current静态类访问

编程入门 行业动态 更新时间:2024-10-17 11:33:48
本文介绍了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静态类访问

本文发布于:2023-11-13 15:03:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1584654.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:静态   HttpContext   Current

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!