Friday, June 22, 2007

System.Security.SecurityException: Request for the permission of type 'System.Net.WebPermission, System, Version=2.0.0.0 in the sharepoint

Situation:

You have a custom ASP.NET code depolying to the sharepoint area. You have added the strong named assembly to the GAC (or) 80/bin. After the iisreset (or) application recycle you see the following error:

Security ExceptionDescription: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application’s trust level in the configuration file.
Exception Details: System.Security.SecurityException: Request for the permission of type ‘System.Net.WebPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′ failed.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


Reason: .NETCAS( Code Access Security) restricts the managed code at the sharepoint cost!

Fix:

Very simple than you imagined!
  1. On the sharepoint server, Go to the folder "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\CONFIG"
  2. Open the config file "wss_minimaltrust.config"
  3. Under the XML section <namedpermissionsets> and under the last <permissionset> add the following:




    <IPermission class="System.Net.WebPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
    version="1"
    Unrestricted="true" >
    </IPermission>
  4. You are all set. (No iisreset/app pool recycle is needed)

No comments:

Post a Comment