从 SPItemEventProperties 打开上下文 SPSite 时出现问题

发布于 2024-09-05 23:00:48 字数 678 浏览 4 评论 0原文

在以下代码中,

// class overrides SPItemEventreceiver    
public override void ItemAdding(SPItemEventProperties properties)
{    
  using (var site = new SPSite(properties.SiteId)) //SiteId is GUID <<corrected
  {
      ...
  }
}

引发以下异常:

System.IO.FileNotFoundException: The Web application at http://URL could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application.

解决此问题的一种方法是对备用访问映射中指定的 URL 进行硬编码(或配置)。将正确的 URL 放入备用访问映射最终是正确的解决方案,但如果可能的话,我需要一种不需要配置的解决方法。

In the following code,

// class overrides SPItemEventreceiver    
public override void ItemAdding(SPItemEventProperties properties)
{    
  using (var site = new SPSite(properties.SiteId)) //SiteId is GUID <<corrected
  {
      ...
  }
}

The following exception is thrown:

System.IO.FileNotFoundException: The Web application at http://URL could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application.

One way to work around this is to hard-code (or configure) the URL specified in Alternate Access Mappings. Putting the correct URL in Alternate Access Mappings is ultimately the correct solution, but if possible, I need a work-around that doesn't require configuration.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

请恋爱 2024-09-12 23:00:48

SiteId 不应是整数 - SPSite ctor 仅接受 URL 或 Guid。鉴于它是一个 GUID,我不明白 AAM 在这里如何发挥作用。另一种方法可能是使用:

properties.OpenWeb().Site

此外,由于您处于同步事件处理程序中,因此您应该有权访问 SPContext.Current.Site (除非您在文档库中捕获事件 - 长期存在的共享点错误意味着没有上下文在 doclibs 的同步事件中 - 糟糕)

-Oisin

SiteId should not be an integer - SPSite ctor only accepts URLs or Guids. Given that it is an GUID, I don't see how AAM plays a part here. An alternate approach might be to use:

properties.OpenWeb().Site

Also, since you are in a synchronous event handler you should have access to SPContext.Current.Site (unless you're trapping events in a document library - a long standing sharepoint bug means there is no context in sync events for doclibs - shitty)

-Oisin

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文