Permission exception during development of custom web parts for WSS 3.0

February 24th, 2009 by ganton | Print

If you develop a custom Web part for the WSS 3.0 and you’d like to manually install it you can get an error as those below.

Request for the permission of type ‘Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c’ failed.

It is a quite common error if the trust level for the web site where you deploy your custom Web part is WSS_minimum. It happens because WSS_minimum trust level doesn’t allow your Web part code to access to SP object model. This trust level is set by default in the web.config file. In the case of this exception an access to SharePointPermission class is not allowed. For more information go to "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\CONFIG" directory and observe both policy files wss_minimaltrust.config and wss_mediumtrust.config. You can find out that in the first one doesn’t grant permissions to SP object model classes but the second one does grant such permissions. If you’d like to have such permission to SP object model you should go to your web site web.config file and find an element named <trust> which will look like this <trust level="WSS_minimal" originUrl="" />. Then you can change the "level" attribute to WSS_medium. Unfortunately, it will not help you if you’d like to have full permissions and in this case you will need to set Full trust level in order to get your custom code to work in the development environment.

More information on trust levels you can find this MSDN article.

Leave a Reply