SharePoint 2010: Visual Studio and SafeControls

SharePoint 2010: Visual Studio and SafeControls

First off, SafeControls are a great feature of SharePoint, they allow for protection against malicious code being able to run on pages within your SharePoint environment. However, on the flipside they can cause some heartburn and lost hours when trying to find out why things aren’t working as expected. This came up in a recent project, where we were leveraging the new Web Templates feature in SharePoint 2010 coupled with decoratively provisioning pages and web parts on those pages when a site is created using one of our custom web templates. The issue we were running into was that certain web parts were throwing an error when you tried to edit or add them to an exiting or newly created publishing page. 

 

 

This error was also visible on pages provisioned with web parts using features leveraged by the Web Templates. At first there were two immediate ways to fix the issue. One was to add the required permission to the Contributor permission level. The second was to have a user with the permission view the pages first. This started to shed some light on the correct resolution. What was found was the “Safe Against Script” was set to false for the package found in SharePoint Project.

 

 

In order for Members or any other group that has the Contributor permission level to modify web parts this value needs to be set to True. This is of course a very good safety check, because if this was allowed then Members, which are usually a lot more people than Designers or an even higher level, would be able to add scripts that could be harmful and SharePoint would not be able to protect against it.

With this fixed, it also fixed the issue with Members not being able to add certain web parts. This was a result of the web parts, when being initialized on a page, trying to set default values under the context of a user with Contributor rights. Again, this typically will work, but with the Safe Against Script being set to False it was giving the error because it was trying to change at least one property of a web parts..

I hope this will help some of you overcome this issue or be able to just understand a little more about SafeControls and SharePoint.

Leave a Comment
  • Please add 4 and 4 and type the answer here:
  • Post
Wiki - Revision Comment List(Revision Comment)
Sort by: Published Date | Most Recent | Most Useful
Comments
  • Gokan Ozcifci edited Revision 4. Comment: title  

  • Richard Mueller edited Revision 3. Comment: Removed (en-US) from title, added tags

  • Craig Lussier edited Revision 2. Comment: added en-US to tags and title

Page 1 of 1 (3 items)
Wikis - Comment List
Sort by: Published Date | Most Recent | Most Useful
Posting comments is temporarily disabled until 10:00am PST on Saturday, December 14th. Thank you for your patience.
Comments
  • images from blogs.catapultsystems.com had to authanticate.

  • Great seen IAfanasov !!

  • Craig Lussier edited Revision 2. Comment: added en-US to tags and title

  • Richard Mueller edited Revision 3. Comment: Removed (en-US) from title, added tags

  • Gokan Ozcifci edited Revision 4. Comment: title  

Page 1 of 1 (5 items)