在以编程方式创建SPWeb时,WebProvisioned事件未触发
-
10-12-2019 - |
题
我有一个webProvimented事件接收器,我在这个事件接收器中做了一些工作。当我以编程方式从控制台应用程序创建新的Web时,似乎事件接收器不会发射?这是预期的情况吗?
解决方案
Possible duplicate of a question on MSDN:
webprovisioned event not firing when subwebs are created programatically or with powershell
Answers from above:
2 things need to consider here
Proper rights of user who runs the power shell command.
Event receiver should not have SPContext object in it. As its null in case of powershell while its available while you directly working through site.
Other notable thing:
Have you tested if the receiver gets triggered but fails to execute? (put a System.Debugger.Break(); at the first line.
Irrelevant to the question, but just to keep the information at one place:
Notes to implementers
Since an event receiver has to be registered with the site collection before it's handlers can execute, the WebAdding and WebProvisioned handlers cannot run when a site collection and its root web site are created.
Ref: SPWebEventReceiver.WebProvisioned method