2
votes

I have created a webpart. However it keeps complain that I have not "registered as safe":

"UnsafeControlException: A Web Part or Web Form Control on this Page cannot be displayed or imported." "could not be found or it is not registered as safe."

Here is manual fix:

I edit this file: C:\inetpub\wwwroot\wss\VirtualDirectories\80\web.config

and I add this:

<SafeControl Assembly="ExampleWebPart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9d97efbc93164680" Namespace="Example_Web_Parts.VisualWebPart1" TypeName="*" Safe="True" SafeAgainstScript="False" />

However, how I can do this through Visual Studio? It stupid always manully add this to web.config file.

1

1 Answers

6
votes

How to: Mark Controls as Safe Controls

Steps:

  • Open your SharePoint project inside visual studio.
  • Select the web part folder for which you want to change the safe control entries in web.config file.
  • Press F4 to open properties window
  • In properties windows there is last entry of properties displaying as Safe Control Entries
  • Click on the eclipse sign in front of Safe Control Entries value.
  • Inside “Safe Control Entries” pop up window, check for Namespace properties inside SafeControlEntry1 properties panel.
  • Change value of namespace property according to your namespace and class and click ok.
  • Save and build the solution and deploy it again.

Now after successful deployment check web.config of site and voilà you’ll find the correct safe type entries of your web part.

Refer this article for details