SPContext in Event Receiver (PortalSiteMapProvider)

1.6k views Asked by At

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?

1

There are 1 answers

0
Kristopher On

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.