Making a WebPart ‘Safe’ via SafeControls

When you are creating web parts and you try to look at it in another browser, you are sometimes prompted with this unwanted message:

Web Part Error: A Web Part or Web Form Control on this Page cannot be displayed or imported. The type <Name of your WebPart>, Version=, Culture=neutral, PublicKeyToken=c7317cce5826e891 could not be found or it is not registered as safe.

There are numerous pages on the internet all saying go to your web.config file. DON’T bother.
To get rid of this annoying error message – the answer lies in your Visual Studio solution – inside your packages file!

  1. In Solution Explorer, open up your ‘Package’ folder. Here you will see a .package file and a template.xml.
  2. Open the package.package file.
  3. There are three tabs along the top; Design; Advanced and Manifest. Click ‘Manifest’.
  4. At the bottom of the ‘Manifest’ screen, there is a ‘+’ button with the text ‘Edit Options’. Click the + button.
  5. At the bottom of the page, there is a hyperlink, highlighted in blue which says ‘Overwrite generated XML and edit manifest in the XML editor’. Click this.
  6. When you have clicked the hyperlink in the above step, you will be prompted with this pop up –

    Press Yes, and this will disable the designer.
  7. Disabling this will encounter you with a screen that has two hyperlinks on. Click Edit manifest in the XML editor.
  8. You should now see an XML file, with the server tags ‘SafeControl’ in them. E.g.
  9. Finally, to make the application ‘safe’, you will need to add Safe=”True” to the SafeControl tag which contains the namespace.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s