SPContext in event receiver (PortalSiteMapProvider)
1 answer
Try this in your event receiver:
var web = properties.Web;
HttpRequest request = new HttpRequest(string.Empty, web.Url, string.Empty);
HttpResponse response = new HttpResponse(new System.IO.StreamWriter(new System.IO.MemoryStream()));
HttpContext impersonatedContext = new HttpContext(request, response);
impersonatedContext.Items["HttpHandlerSPWeb"] = web;
HttpContext.Current = impersonatedContext;
SPContext context = SPContext.GetContext(impersonatedContext);
You can get SPContext from it.
+2
source to share