我TREID使用的HttpContext在dataAceess层,但我不能创造从HttpContext的使用的HttpContext在数据访问层
HttpContext httpContext = HttpContext.Current;
我创造一个Web应用程序和libery项目对象,我想使用的HttpContext在libery项目像这样:
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
使从GetContextPerRequest()一个对象A的数据访问层应不** **可以根据一个面向UI组分上类似'HttpContext'。这样做只会强制将“数据访问层”绑定到ASP.NET Web应用程序 - 您无法将其用于例如WCF服务或WPF应用程序....我会认为这是一个非常非常糟糕的设计... – 2012-04-15 14:05:08
最简单的解决方案是添加一个对System.Web的引用 – 2013-02-21 04:56:17