I treid to use HttpContext in dataAceess layer but i cant creat a object from HttpContext
HttpContext httpContext = HttpContext.Current;
I creat a web application and a libery project and i want to use HttpContext in libery project like this :
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;
}
}
I use .net 4.
I solve my problem in this way :