Reputation: 14112
I'm trying to write an event receiver which uses the PortalSiteMapProvider. Without having HTTPContext or SPContext INSIDE the event receiver, how would one go about accessing the PortalSiteMapProvider?
Upvotes: 2
Views: 1626
Reputation: 858
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 should be able to get your SPContext from that.
Upvotes: 2