I have created an web event receiver but the webprovisioned event handler fires twice. I have set the scope to web, but it still fires twice.

Problem 1

This is elements file:

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Receivers Scope="Web">


    public override void WebProvisioned(SPWebEventProperties properties)
    SPWeb web = (SPWeb)properties.Web
web.Navigation.UseShared = true;

I saw another post which mentioned that if the scope is set to web it will fire only once, but it my case it is still firing.

Update 1

I tried the following code. It sets the options correctly, but they are not applied to the UI yet. I have to click OK once again to see the changes.

Just to be sure that you guys get what I am trying to achieve. I am trying to set the top navigation, not the left navigation.

                    // PublishingWeb Navigation
                    var pubWeb = PublishingWeb.GetPublishingWeb(web);

                    var webNavigationSettings = new WebNavigationSettings(web);

                    webNavigationSettings.GlobalNavigation.Source = StandardNavigationSource.InheritFromParentWeb;

                    webNavigationSettings.CurrentNavigation.Source = StandardNavigationSource.PortalProvider;
                    pubWeb.Navigation.CurrentIncludeSubSites = true;
                    pubWeb.Navigation.CurrentIncludePages = true;
                    pubWeb.Navigation.CurrentDynamicChildLimit = 20;

                    pubWeb.IncludeInGlobalNavigation = true;
                    pubWeb.Navigation.InheritGlobal = true;
                    pubWeb.Navigation.GlobalIncludeSubSites = true;
                    pubWeb.Navigation.GlobalIncludePages = true;

                    webNavigationSettings.AddNewPagesToNavigation = false;
                    webNavigationSettings.CreateFriendlyUrlsForNewPages = false;


Problem 2

When I create a new site the top navigation does not get applied to this newly created site.Any ideas?

2 Answers 2


You might have a couple instances of the same event receiver attached. You can check by running the following PowerShell commands and look for duplicates:

If you attach event receivers to a site collection:

Add-PSSnapin microsoft.sharepoint.powershell
$site = Get-SPWeb http://webapp/sites/SiteCollection
$site.EventReceivers | sort Type | ft Class, Type

If you attach event receivers to a web:

Add-PSSnapin microsoft.sharepoint.powershell
$web = Get-SPWeb http://webapp/sites/SiteCollection/web
$web.EventReceivers | sort Type | ft Class, Type

For your second problem, try using the following code:

var web = properties.Web as SPWeb;
var pubWeb = PublishingWeb.GetPublishingWeb(web);
pubWeb.InheritGlobalNavigation = true;


var web = properties.Web as SPWeb;
var pubWeb = PublishingWeb.GetPublishingWeb(web);
pubWeb.Navigation.InheritGlobal = true;

You might need to update web object as well.

Hope this helps.


Problem 1

The EventReceiver is normal. Please change the scope of your Feature where the EventReceiver is provisioned from Web to WebApplication Scope or create a new one and add your EventReceiver to a WebApplication scoped Feature.

Problem 2

And here is the solution for your navigation problem https://msdn.microsoft.com/en-us/library/office/ms196088(v=office.14).aspx.

childWeb.Navigation.UseShared = true;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.