有没有办法模仿ThreadStatic与HttpContext.Current.Items用? [英] Is there any way to imitate ThreadStatic for use with HttpContext.Current.Items?

查看:143
本文介绍了有没有办法模仿ThreadStatic与HttpContext.Current.Items用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于主题敏捷的在ASP.Net, ThreadStatic 不是一个适当的机制在web应用中使用的隔离静态属性访问从一请求到下一​​个。

Because of Thread Agility in ASP.Net, ThreadStatic is not an appropriate mechanism to use in web applications for segregating static property access from one request to the next.

为了避免大量的电话,以 HttpContext.Current.Items 和相关null检查等等,有没有由.NET Framework提供的任何挂羊头卖狗肉,由此我可以创建一个类的工作方式类似于 ThreadStatic 属性,但使用 HttpContext.Current.Items 如果当前code目前正在一个ASP.Net请求上下文中执行?

In order to avoid lots of calls to HttpContext.Current.Items and the associated null checks and so forth, is there any trickery offered by the .Net framework whereby I could create an attribute which works sort of like ThreadStatic, but utilises HttpContext.Current.Items if the current code is being executed within an ASP.Net request context?

注:我知道ThreadStaticAttribute是一个特例,没有功能$ C $内部c和由之前它的任何神奇的是工作的JIT编译器检查

推荐答案

该n2cms项目具有的 AdaptiveContext类建出来,你可能有一个看一下。我知道有这样做的log4net的类似的一些谈话,但我不知道是否已经完成。

The n2cms project has an AdaptiveContext class built out which you might have a look at. I know there was some talk of doing something similar in log4net, but I'm not sure if that was completed.

没有内置的框架,不过,据我可以告诉。

Nothing built into the framework, though, as far as I can tell.

这篇关于有没有办法模仿ThreadStatic与HttpContext.Current.Items用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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