Add and Remove Web.config SafeControls Programmatically

2.5k views Asked by At

I am using this link http://msdn.microsoft.com/en-us/library/bb861909.aspx

The adding a SafeControl to the web.config works good. But the removing does not work! What is wrong?

Here in comments you can see the same problem http://blog.thekid.me.uk/archive/2007/03/20/removing-web-config-entries-from-sharepoint-using-spwebconfigmodification.aspx

2

There are 2 answers

0
Per Jakobsen On BEST ANSWER

If removing entries added using SPWebConfigurationModifications (SPWCM) fails the cause is usually:

  1. The SPWCM entries has been added more times than they have been removed
  2. The Name field in the SPWCM isn't a correct XPath to find the elements within the Path

But an other question is why do you want to add SafeControl entries using code?

SafeControl entries should be added by entries in the manifest.xml of the WSP package which adds the dll

0
Mistlin On

I tried modifying the manifest.xml file to change the SafeControl because I had changed the namespace for the webpart. Unfortunatly when I did a Deploy it kept overwritting the changes I made in the manifest.xml file. To change the namespace of a webpart so it gets compiled to the manifest.xml file correctly click on the webpart in your Visual Studio 2010 project and edit the Safe Control Entries section and in there you can modify the namespace.