我想在 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。