I have a WebProvisioned event receiver and i do some work in this event receiver. When i create new webs from a console application programmatically, it seems the event receiver does not fire? Is this an expected situation?
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