concept CAS in category sharePoint

appears as: CAS
SharePoint 2010 Web Parts in Action

This is an excerpt from Manning's book SharePoint 2010 Web Parts in Action.

So far in this book you’ve deployed Web Parts as full-trust solutions or into the very limited sandbox. Previous versions of SharePoint didn’t have a sandbox, and to deploy solutions under a more restricted security policy you deployed them into the web application’s bin folder as a partial trust assembly. This is still a valid option if you need to have a security level that’s not as strict as the sandboxed solution but not as fully trusted as farm solutions. Deploying partial trust solutions requires that you manually configure the security policy for your assembly using custom Code Access Security (CAS) policies. Although this approach can look like hard work at first, it’s a well-documented process.

The security level of the web application is configured by the trust element in the web.config file and by custom Code Access Security (CAS) policies. By default, web.config defines the WSS_Minimal security level:

<trust level="WSS_Minimal" originUrl="" />

This is a default minimal level of security defined by SharePoint. The WSS_Minimal CAS policy is located in the {SharePoint Root}\Config\ and is called WSS_MinimalTrust.config. You shouldn’t change this file or the other policy files. If you need to manually change the settings, make a copy of them and edit the copy. The WSS_Minimal trust level restricts the code from accessing the SharePoint object model and resources such as the file system and database connections.

CAS policies can be quite hard to maintain, and it isn’t always obvious who’s responsible for creating CAS policies: the developer or the administrator of the farm. Most often the developer creates the CAS policies, because few SharePoint administrators know how to read and interpret CAS policies. This essentially makes the CAS policies useless. The whole purpose of using such policies is that the administrator who owns the SharePoint farm sets the security level of the solution.

To test the CAS policies, let’s change the Label control in our Web Part so that it prints the name of the current site. Change the Text property so that it looks like this: