There are two places where we can deploy custom webpart assembley in order to use it in SharePoint.
a. deploy it to Global Assembley Cache
b. copy it to bin directory of relevant web application.
and there are 2 ways to set trust level
a. change default trust level from WSS_Minimal to WSS_Midium or WSS_Full manually in web.config
b. create custom access policy and deploy it to web.config.
Now, here is the code you can use to deploy your custom access policy in web.config
<CodeAccessSecurity>
<PolicyItem>
<PermissionSet class="NamedPermissionSet" version="1" Description="Permission set for custom test WebParts">
<IPermission class="AspNetHostingPermission" version="1" Level="Minimal" />
<IPermission class="SecurityPermission" version="1" Flags="Execution" />
<IPermission class="Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" version="1" ObjectModel="True" />
<IPermission class="System.Net.WebPermission, System, version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1">
<ConnectAccess>
<URI uri="https?://.*" />
</ConnectAccess>
</IPermission>
<IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="ControlThread, UnmanagedCode" />
<IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Read="UserName" />
</PermissionSet>
<Assemblies>
<Assembly Name="HelloWorld" />
</Assemblies>
</PolicyItem>
</CodeAccessSecurity>
You can only have one CAS policy per solution package but can have mulitple asseblies in it. It is always good practice to use CAS policy instead of doing manual changes as it applies to all the assemblies in the bin directory of web application.
Sunday, 16 May 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment