Sunday, April 5, 2009

Error:Request for the permission of type 'System.Net.WebPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed

Problem: when I try to read xml file on the server through custom webpart on the portal ,it give below error.

“Error:Request for the permission of type 'System.Net.WebPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.”

Cause: The default trust level on our test site is set to wss_minimal which does not grant us permissions to use the SharePoint Object Model from the code.

To solve this error :

There are three different ways to get over this permission problem: we can add our assembly to the GAC to run under full trust, change our web.config and set the trust level to Full, or create a custom trust level by modifying wss_minimaltrust.config with just enough trust to get our code working.
Web Part Deployment Options, the third option is the recommended approach we will take to resolve our problem.

You'll have to add these lines to the medium trust file (or a custom trust file):

<ipermission class="System.Net.WebPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1">
< connectaccess>
< uri uri="http://myserver:myport/mysitecollection\mywebservice.asmx">
</connectaccess>
</ipermission>


The path of the trust files can be found in the web.config. In my case it was:
C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\CONFIG

You can add multiple url's

No comments: