我正在尝试编写一个使用 PortalSiteMapProvider 的事件接收器。如果事件接收器内部没有 HTTPContext 或 SPContext ,如何访问 PortalSiteMapProvider?
问问题
1608 次
1 回答
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 。
于 2011-11-15T22:46:51.893 回答