2

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?

LB.
  • 13,730
  • 24
  • 67
  • 102

1 Answers1

2

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.

Kristopher
  • 819
  • 14
  • 31