CAS Policy for Webparts in Sharepoint 2010

If a Web Part needs some specific CAS policy (Code Access Security) , you can add the information to the deployment package. In addition, the administrator must provide the -allowCasPolicies parameter when installing the solution using the stsadm tool.

Note : Sandboxed solutions do not allow overwriting the CAS policy.

To use a custom CAS policy, do the following:

1.Change the installation target to WebApplication - First, set the Assembly Deployment property of the current Web Part project to WebApplication. This deploys the assembly—not into the GAC, but into a less trusted file location of your project target.

2. Add the CAS policy XML to the package - Second, add the custom policy to the package designer. Open the package designer by double-clicking Package.package. Then select the Manifest tab and enter the CAS data into the template windows.

3. Set the assembly attribute, AllowPartiallyTrustedCallers - Third, add the required attribute to the assemblyinfo.cs file:
[assembly: AllowPartiallyTrustedCallers()]

4. Finally, build and deploy the package again -
You can now add it to the current installation and use the formerly blocked classes. The CAS policy should be completed to allow at least the typical permissions a Web Part demands.It’s necessary to add all these permissions because the custom CAS file does not merge. Instead, it replaces the common definitions. Thus, the definition must contain all permissions required to execute the Web Part.

0 comments:

Post a Comment

Disclaimer

This is a personal weblog. The opinions expressed here represent my own and not those of my employer or anyone else. Should you have any questions or concerns please e-mail me at sharepointprogrammingblogger@gmail.com .

Copyright (c) 2010 @ myshaepointwork.blogspot.com. All rights are reserved.Do Not Copy.

@ Learning SharePoint.com