【问题标题】:SPContext in Event Receiver (PortalSiteMapProvider)事件接收器中的 SPContext (PortalSiteMapProvider)
【发布时间】:2009-10-08 15:25:02
【问题描述】:

我正在尝试编写一个使用 PortalSiteMapProvider 的事件接收器。如果没有 HTTPContext 或 SPContext INSIDE 作为事件接收器,如何访问 PortalSiteMapProvider?

【问题讨论】:

  • 我会对如何在没有 SPContext 对象的情况下使用事件接收器更感兴趣。请解释一下。
  • 事件接收器中没有 SPContext。
  • 您使用的是哪种类型的活动?
  • 您可以从 SPItemEventProperties 确定 web 和列表
  • 但是您没有 SPContext 来使用 PortalSiteMapProvider。获取对 web/list 的引用不给我上下文。

标签: sharepoint portalsitemapprovider spcontext


【解决方案1】:

在你的事件接收器中试试这个:

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。

【讨论】:

    猜你喜欢
    • 2012-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-08
    • 2016-05-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多