从 SPItemEventProperties 打开上下文 SPSite 时出现问题
在以下代码中,
// 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
SiteId 不应是整数 - SPSite ctor 仅接受 URL 或 Guid。鉴于它是一个 GUID,我不明白 AAM 在这里如何发挥作用。另一种方法可能是使用:
此外,由于您处于同步事件处理程序中,因此您应该有权访问 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:
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