SPItemEventReceiver 上下文 SiteId/WebUrl 不正确

发布于 2024-08-16 05:20:42 字数 1007 浏览 6 评论 0原文

我创建了一个在项目更新时触发的 SharePoint 事件接​​收器。 接收者需要访问 AfterProperties 和 ListItem。

使用 IP 地址 (http://10.0.4.50/sites/),当访问 SPItemEventProperties 中的 SiteId 和 WebUrl 时,它会抛出 FileNotFoundException找不到 http://10.0.4.50/sites/companyName 的 Web 应用程序。验证您是否正确键入了 URL。

使用在网站集设置中指定的主机名触发事件接收器时http://computerhostname/sites/companyName。这工作正常,没有抛出异常。

//Combine Both AfterProperties And ListItem
var ListProperties = new List<KeyValuePair<string, object>>();
ListProperties.AddRange(properties.AfterProperties.ToKeyValue());
ListProperties.AddRange(properties.ListItem.ToKeyValue(p => !p.Sealed));
var AvaliableProperties = ListProperties.Distinct(new KeyValueComparer<object>());

I have created a SharePoint Event Receiver, that fires on Item Update.
The receiver needs access AfterProperties and ListItem.

When firing the event receiver from a SharePoint web application using an IP address (http://10.0.4.50/sites/), it throws a FileNotFoundException, when accessing SiteId And WebUrl in SPItemEventProperties.
The Web application at http://10.0.4.50/sites/companyName could not be found. Verify that you have typed the URL correctly.

When firing the event receiver using the hostname, specified at setup of Site Collection http://computerhostname/sites/companyName. This works fine, no exception is thrown.

//Combine Both AfterProperties And ListItem
var ListProperties = new List<KeyValuePair<string, object>>();
ListProperties.AddRange(properties.AfterProperties.ToKeyValue());
ListProperties.AddRange(properties.ListItem.ToKeyValue(p => !p.Sealed));
var AvaliableProperties = ListProperties.Distinct(new KeyValueComparer<object>());

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

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

发布评论

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

评论(2

以歌曲疗慰 2024-08-23 05:20:42

这不一定是 SharePoint 问题,但很可能是由于主机上的 IIS 配置方式造成的。特定站点可以“绑定”到 IP 地址和主机名,如果浏览器发送的 HTTP GET 中不存在主机名,则 IIS 将返回 404 NOT FOUND

您可以通过使用浏览器查看是否可以通过 IP 地址访问该网站来验证这一点。

如有必要,您可以添加其他绑定,但每个 IP 地址只能有一个“默认”绑定,因此(在您的情况下)10.0.4.50 处只能存在一个站点。

解决存在多个站点但无法使用主机名的情况的一种可能方法可能是为该 IP 添加到端口 80 以外的端口的绑定,因此您的 URL 将变为类似 http:// 10.0.4.50:8080/sites/companyName

This isn't necessarily a SharePoint problem, but is most likely down to the way that IIS is configured on the host. A particular site can be "bound" to an IP address and a host name, and if the host name isn't present in the HTTP GET sent by the browser then IIS will return a 404 NOT FOUND.

You can verify this by using a browser to see whether you can access the site by IP address.

You can add additional bindings if necessary, but there can only be one "default" binding per IP address, so only one site can be present at (in your case) 10.0.4.50.

A possible way around the situation where multiple sites are present but you can't use a hostname might be to add a binding to a port other than port 80 for this IP, so your URL would become something like http://10.0.4.50:8080/sites/companyName.

禾厶谷欠 2024-08-23 05:20:42

这不仅仅是 IIS 的问题,也与 Sharepoint 有关。 SharePoint 中的许多引用都是通过使用 url 作为起点来完成的(只需查看 SPSite 的构造函数即可)。然后将该 URL 与 SharePoint 配置数据库中的已知 URL 进行比较。 (以及网站内容数据库中的 ofr 文件等)。

SharePoint 使用称为备用访问映射的系统将不同的 URL 分配给 Web 应用程序的“区域”(默认、Intranet、Internet...自定义定义)。如果它找不到“确切的”Url,内部的东西将会失败(尤其是搜索非常“Url 敏感”)。

然后 IIS 部分发挥作用:由于 IIS 可能没有其他站点在 80 端口上运行,并且没有特定的主机头(因此默认为机器名),或者主机头设置为机器名,IIS 将接收请求由于 SharePoint 绑定到此 Web 应用程序,SharePoint 将尝试处理它,查找 url,Sharepoint 找不到 url,因此“中断”。

当您在 SharePoint 中创建新的 Web 应用程序时将主机头字段留空时,会出现无主机头的情况。

This is not just an IIS problem, but Sharepoint related as well. A lot of referencing in SharePoint is done by using a url as a starting point (just look at the constructor of SPSite). The url is then compared to known url's in SharePoint's Config database. (and ofr files etc in the site's content database).

SharePoint uses a system called Alternate Access Mappings to assign different urls to a Web Application's "Zones" (default, intranet, internet, ... custom definition). If it does not find the 'exact' Url, internally stuff will fail (And especially search is very "Url sensitive").

Then comes the IIS part into play: Since IIS probably has no other site running on the 80 port, and without a specific hostheader (so it defaults to machinename), or with the hostheader set to the machine name, IIS will pick up the request and since SharePoint is tied into this webapp, SharePoint will try to process it, looks up the url, Sharepoint does not find the Url and thne "breaks".

The no hostheader occurs when you leave the hostheader field empty when you create a new web app in SharePoint.

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