views:

317

answers:

2

Just created a WSS site with a some custom web-parts. But I get an error: ...dont have the trust level. I edited the safecontrols section from the web.config file of the virtual server, but to no avail.

+1  A: 

Web parts operate under the ASP.NET Code Access Security model. They have to be trusted as well as marked as safe controls in order to execute.

There are two recommended ways to solve this:

  1. Deploy to the Global Assembly Cache (GAC). This is quick and easy but also means your code is fully trusted across the server. Any other code on the server could execute the methods in your classes, potentially creating a security risk.

  2. Deploy to the web application bin folder and write a Code Access Security file. This allows you to secure your code to execute with full trust (or even further restrictions). It will also only be able to execute within the SharePoint web application. The downside is this takes more time to set up. There is information on Microsoft's site about this and plenty more on the web (some of which is probably more helpful than what MS provide).

(As an aside, never set your web application to full trust in web.config. This would mean any arbitrary code will be able to do anything on the server - a serious security risk.)

Alex Angas
Thanks for your post
Erich
+1  A: 

I have a basic web part solution and it works fine with default trust. However, as soon as I add a cas policy to the solution manifest.xml, the site collection that I deploy the solution to no longer functions, it gives a SharePointPermission denied error. Why does this happen?