Create your own Custom Code Access Security Policy for SharePoint web part

1.First, goto the CONFIG folder in your 12 Hive.There you will see the two standard security config files:
wss_mediumtrust.config and wss_minimaltrust.config.

2. Copy the WSS_Minimal policy file stored at “C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions12configwss_minimaltrust.config”

3. Rename to MyCustomPolicy_Minimal.config

4. Open and added the following entries under the code group section:

5.First, locate the NamedPermissionSets section.  At the bottom of this section, add the following:






6. In the config file, find the CodeGroup tags.  There may be a few of them.  The first one will be something like:

.

Below it are other CodeGroups.  We are going to add a new CodeGroup in this section for our assembly.

So copy the following code:


Paste this just after the FirstMatchCodeGroup CodeGroup.  This is important that you paste it after the “FirstMatchCodeGroup” since all of the other CodeGroups are “UnionCodeGroups”.  This is worth noting because depending on the type of UnionCodeGroup, its criteria may be broad enough to encompass your new assembly and once it is accepted by a CodeGroup it stops looking.  So if you put your new CodeGroup last, odds are that your changes will never be seen.  So, make sure it’s the first CodeGroup.

7. Save your config file cause we’re done with it.

8. In the web.config, add


to the securityPolicy section and change


To


9. Save the web.config and do issreset

Related Post

1 thought on “Create your own Custom Code Access Security Policy for SharePoint web part

  1. Do we have to add this in every config files in a farm.
    Where did you add reference to your Custom Webpart.
    How do i add this security access to my specific webpart or solution.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.