gpt4 book ai didi

asp.net - 在数据访问层中使用 Httpcontext

转载 作者:行者123 更新时间:2023-12-04 05:50:11 25 4
gpt4 key购买 nike

我尝试在 dataAceess 层中使用 HttpContext 但我无法从 HttpContext 创建对象

 HttpContext httpContext = HttpContext.Current;

我创建了一个 Web 应用程序和一个 libery 项目,我想在 libery 项目中使用 HttpContext,如下所示:
public static Context GetContextPerRequest()
{

HttpContext httpContext = HttpContext.Current;
if (httpContext == null)
{
return new Context();
}
else
{
int contextId = Thread.CurrentContext.ContextID;
int hashCode = httpContext.GetHashCode();
string key = string.Concat(hashCode, contextId);

Context context = httpContext.Items[key] as Context;
if (context == null)
{
context = new Context();
httpContext.Items[key] = context;
}

return context;
}
}

我使用.net 4。

最佳答案

你可以解析 HttpContext.Current从表示层并更改您的方法如下。如果您需要找到一种方法来访问当前的 http 上下文 this链接会帮助你。

   public static Context GetContextPerRequest(HttpContext httpContext)
{
------
------
}

关于asp.net - 在数据访问层中使用 Httpcontext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10162155/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com