我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