c# - 在 Thread Local Storage/HttpContext Current Items 中存储数据

标签 c# asp.net httprequest thread-local-storage

在Thread-Local Storage 或HttpContext.Current.Items 中存储数据,哪个更高效……?
这用于在 Web 应用程序中存储主数据/参数。
在这两种方法中放置数据的代码是:

1。 System.Web.HttpContext.Current.Items

public static void Add(string pName, object pValue)
{
    System.Web.HttpContext.Current.Items.Add(pName, pValue);
}

2。 TLS

public static void Add(string pName, object pValue)
{
    Thread.SetData(Thread.GetNamedDataSlot(pName), pValue);
}


谢谢....

最佳答案

如果您正在考虑线程安全,请选择线程本地存储。如果不需要线程安全,则 HttpContext.Current 选项很有用。

关于c# - 在 Thread Local Storage/HttpContext Current Items 中存储数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16097913/

相关文章:

c# - 如何解析 KML 文件以从 Placemark 元素检索坐标点?

c# - 更改 List<Texture> 的项目会创建一个新项目

c# - 表达式引用了不属于 ISearchIndexClient.Documents.Search 方法的模拟对象的方法

c# - 在 ASP.NET MVC 应用程序中使用 Web.config 而不是 app.config 进行集成测试

api - Binance API key

java - Spring org.springframework.web.multipart.support.MissingServletRequestPartException,所需的请求部分 'file' 不存在

c# - 复杂对象的自动映射器映射

c# - Javascript QueryString 到 c#

asp.net - 如何在asp中设置单元格的样式:DataGrid?

python - 测试 Django : reason for unexpected http status code