我正在尝试编写一个使用PortalSiteMapProvider的事件接收器。如果没有HTTPContext或SPContext INSIDE 事件接收器,那么如何访问PortalSiteMapProvider呢?
答案 0 :(得分:2)
在您的事件接收器中尝试此操作:
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);
您应该可以从中获取SPContext。