I have to add a custom webpart to master page programmatically. I tried to go common way using:

web.GetLimitedWebPartManager("/_catalog/masterpages/default.master", PersonalizationScope.Shared)

but it says that the URL in incorrect. I have also tried url like

web.Url + "/" + web.MasterUrl

but it still doesn't work. If works perfectly with default.aspx (but webpart is shown only on the homepage not in all pages and it's clear why), so I suppose the problem is that the page has '.master' extension.

What is a correct way to add webpart to master page? I need this webpart to be located on every site page, not only on the homepage.

Thx in advance


As per MSDN: You cannot add Web Parts in zones to a master page. You can add static Web Parts (parts outside of a zone) to a master page, but you cannot add dynamic Web Parts to master pages. The better way to do this is using Delegate Controls and the AdditionalPageHead delegate control can be the best candidate as it is available in all OOB master pages.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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