Webprovisioned not fire
-
08-12-2019 - |
Pergunta
I have a code from external developer that creates site in list event receiver.
public override void ItemAdded(SPItemEventProperties properties)
{
bool EventFiringEnabledStatus = EventFiringEnabled;
ReceiverParams param = new ReceiverParams(properties);
EventFiringEnabled = false;
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(properties.SiteId))
{
using (SPWeb web = site.OpenWeb(properties.Web.ID))
{
if (!IsWebExists(web, name))
{
bool allowUnsafeUpdates = web.AllowUnsafeUpdates;
try
{
web.AllowUnsafeUpdates = true;
SPWebCollection collection = web.Webs;
SPWeb projectWeb = collection.Add(name, title, description, culture_LCID, templateName, true, false);
projectWeb.Update();
isCreated = true;
}
finally
{
web.AllowUnsafeUpdates = allowUnsafeUpdates;
}
}
}
}
});
}
finally
{
EventFiringEnabled = EventFiringEnabledStatus;
}
}
I want to customize the site using WebProvisioned event receiver:
public override void WebProvisioned(SPWebEventProperties properties)
{
System.Diagnostics.Debugger.Break();
base.WebProvisioned(properties);
}
This event fires when i create site from web interface or from my own code. But it does not fires when the site is created in list event receiver. There is only "Error loading and running event receiver : Thread was being aborted." in logs.
Solução
You may want to check if the Event Receiver is registered (using SharePoint Manager) and verify if it needs to be scoped at Site level rather than at Web level (the Webprovisioned event does not get fired for the root web). Here's a good post giving details on WebProvisioned event receiver – a practical example.
UPDATE: The differences in the two scenarios may lie in the context (HTTPContext v. SPContext) - this can be verified by posting events in the ULS logs.
Outras dicas
This row
EventFiringEnabled = false;
is telling the code to not fire the WebProvisioned event, so that is why your event receiver does not trigger.