HttpContext in SPItemEventReceiver

20/10/2012 21:01

 

 //to get Current HttpContext insied of SPItemEventReceiver... (HttpContext.Current is always null as this is asynchronous event receiver)
                HttpRequest request = new HttpRequest(string.Empty, properties.Web.Url, string.Empty);
 
//both version are working
                writer = new StringWriter();
                //HttpContext.Current = new HttpContext(request, new HttpResponse(writer));
                //SPWeb web = properties.Web;
                //HttpContext.Current.Items["HttpHandlerSPWeb"] = web;
                //CacheUtility cUtil = new CacheUtility(HttpContext.Current);
 
                var httpContext = new HttpContext(request, new HttpResponse(writer));
                CacheUtility cUtil = new CacheUtility(httpContext);