Event Receiver(scope to web), when deployed, it attached to list however it also attach to site

440 views Asked by At

Hi I've a event receiver that is scope to web.

On development environment, i deploy and it manage to attach to only a specific list, it will only trigger from this specific list.

However when i deploy to production, it manage to attach to the list(check from PowerShell, there's no duplicate), however it also attach to the site(my assumption), and it will trigger from any list.

I had deployed the same wsp twice, once is scope to site, after that i change it to scope to web and redeploy.

Result in production environment now:

  • event receiver will trigger from all list

  • on the specific list it will trigger twice, i believe because it(event receiver) is attached to that specific list and at the same time it is attached to the site, hence triggered twice. (there's no update in the ER, only sending email)

expected result:

  • only trigger on specific list and trigger only once

Elements.XML:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Receivers ListUrl="/ISD/Lists/ICForm">
      <Receiver>
        <Name>Email_EventItemAdded</Name>
        <Type>ItemAdded</Type>
        <Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
        <Class>IC___Event_Receiver.Email_Event.Email_Event</Class>
        <SequenceNumber>10000</SequenceNumber>
      </Receiver>
      <Receiver>
        <Name>Email_EventItemUpdated</Name>
        <Type>ItemUpdated</Type>
        <Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
        <Class>IC__Event_Receiver.Email_Event.Email_Event</Class>
        <SequenceNumber>10000</SequenceNumber>
      </Receiver>
  </Receivers>
</Elements>

Feature Manifest:

<Feature xmlns="http://schemas.microsoft.com/sharepoint/" Scope="Web" Title="IC - Event Receiver Feature" Id="aef9e351-e707-4848-927d-6f5d525aab1a">
  <ElementManifests>
    <ElementManifest Location="Email Event\Elements.xml" />
  </ElementManifests>
</Feature>

Package.Template.XML:

<?xml version="1.0" encoding="utf-8"?>
<Solution xmlns="http://schemas.microsoft.com/sharepoint/">
<Assemblies>
<Assembly Location="IC - Event Receiver.dll" DeploymentTarget="GlobalAssemblyCache">
<SafeControls>
<SafeControl Assembly="$SharePoint.Project.AssemblyFullName$"
Namespace="$SharePoint.Project.FileNameWithoutExtension$" TypeName="*" Safe="True"></SafeControl>
</SafeControls>
</Assembly>
</Assemblies>
</Solution>

Anyone experience issue like this? or any advice on how to solve this?

Thanks

1

There are 1 answers

7
Lee On

If you want to limit the event receiver attaches to specific list, use ListUrl to specific the list.

For example:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Receivers ListUrl="/Lists/customlist">

And make sure you disable event firing when you update list item in proper event receiver, one thread for your reference