我的事件接收器也有同样的问题。我尝试了 ListTemplateId、ListTemplateOwner,甚至 ListUrl。我知道这些设置是有效的,但是它们被忽略了,并且接收器被附加到每个列表中。
我有一种预感,它可能与在站点范围功能中声明的事件接收器有关。SPEventElement的“文档”似乎证实了这一点:
switch (this.FeatureDefinition.Scope)
{
case SPFeatureScope.Site:
if (this.SiteScopedReceivers())
{
this.UpdateEventReceiversForSite(site, sqlcmdAppendOnly, new SPEventElement.GetSqlToUpdateEventReceiversForSite(this.GetEventReceivers(site.RootWeb).GetSqlToAddEventReceiversToSite));
break;
}
else
{
this.UpdateEventReceiversForWeb(site.RootWeb, sqlcmdAppendOnly, new SPEventElement.GetSqlToUpdateEventReceiversForWeb(this.GetEventReceivers(site.RootWeb).GetSqlToAddEventReceiversToWeb));
break;
}
case SPFeatureScope.Web:
if (this.RootWebOnly && !web.IsRootWeb)
{
ULS.SendTraceTag(1718513714U, (ULSCatBase) ULSCat.msoulscat_WSS_General, ULSTraceLevel.Verbose, "Event Receivers in Feature '{0}' were not activated because current web is not the root web.", new object[1]
{
(object) this.FeatureDefinition.Id.ToString("B")
});
break;
}
else
{
bool templateIdExists;
int templateId;
this.CheckTemplateId(out templateIdExists, out templateId);
if (!templateIdExists)
{
if (this.ListUrl != null)
{
this.UpdateEventReceiversForList(web, sqlcmdAppendOnly, new SPEventElement.GetSqlToUpdateEventReceiversForList(this.GetEventReceivers(web).GetSqlToAddEventReceiversToList), true);
break;
}
else
{
this.UpdateEventReceiversForWeb(web, sqlcmdAppendOnly, new SPEventElement.GetSqlToUpdateEventReceiversForWeb(this.GetEventReceivers(web).GetSqlToAddEventReceiversToWeb));
break;
}
}
else
{
if (this.ListUrl != null)
throw new SPException(SPResource.GetString("ElementHasBothTemplateIdAndUrl", new object[0]));
this.UpdateEventReceiversForListTemplate(templateId, web, sqlcmdAppendOnly, new SPEventElement.GetSqlToUpdateEventReceiversForList(this.GetEventReceivers(web).GetSqlToAddEventReceiversToList));
break;
}
}
}
对于站点范围的功能,似乎忽略了 ListTemplateId、ListTemplateOwner 和 ListUrl。当我将事件接收器元素移动到 Web 范围的功能时,接收器仅正确附加到所需的列表。