Hi,
Don't change the trust level to Full in web.config and deploy your web parts to GAC as it is not recommended practise in most of the cases. Instead you should create CAS policy.
Example to add a CAS Policy for a sample WebPart.
Strong name the webpart and find out it's public key blob using sn -Tp assembly name.
Then in manifest.xml file for the Solution(WSP) put following entry.
<Solution
SolutionId="b172f003-d6c7-3e13-f737-a5d84a02e3e5" xmlns="http://schemas.microsoft.com/sharepoint/">
SolutionId="b172f003-d6c7-3e13-f737-a5d84a02e3e5" xmlns="http://schemas.microsoft.com/sharepoint/">
<!--Solution
created by InstallAssemblies.exe on 8/15/2006 7:03:53 PM-->
created by InstallAssemblies.exe on 8/15/2006 7:03:53 PM-->
<Assemblies>
<Assembly Location="MyCustomWebParts.dll" DeploymentTarget="WebApplication">
<ClassResources>
<ClassResource Location="MyCustomWebParts.pdb"
/>
/>
<ClassResource Location="en\two\generic.txt" />
<ClassResource Location="de\two\specific.txt" />
<ClassResource Location="header.html" />
</ClassResources>
<SafeControls>
<SafeControl Assembly="MyCustomWebParts,
version=1.0.0.0, Culture=neutral, PublicKeyToken=636addc00401d15b" Namespace="Example.CodeAccessSecurity" TypeName="*" />
version=1.0.0.0, Culture=neutral, PublicKeyToken=636addc00401d15b" Namespace="Example.CodeAccessSecurity" TypeName="*" />
</SafeControls>
</Assembly>
</Assemblies>
<DwpFiles>
<DwpFile Location="StandardAspNetWebPart.webpart" />
<DwpFile Location="HybridWSSWebPart.webpart" />
<DwpFile Location="StandardWSSWebPart.dwp" />
</DwpFiles>
<CodeAccessSecurity>
<PolicyItem>
<PermissionSet class="NamedPermissionSet"
version="1" Description="Permission
set for custom test WebParts">
version="1" Description="Permission
set for custom test WebParts">
<IPermission class="AspNetHostingPermission"
version="1" Level="Minimal" />
version="1" Level="Minimal" />
<IPermission class="SecurityPermission"
version="1" Flags="Execution" />
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" />
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">
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" />
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"
/>
mscorlib, version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1" Read="UserName"
/>
</PermissionSet>
<Assemblies>
<Assembly
PublicKeyBlob="hexadecimalValueTruncatedForClarity"
/>
PublicKeyBlob="hexadecimalValueTruncatedForClarity"
/>
</Assemblies>
</PolicyItem>
</CodeAccessSecurity>
</Solution>
- There can only be 1 CodeAccessSecurity node per Solution manifest.
- There can be any number of PolicyItem nodes.
- Each PolicyItem node can contain only 1 PermissionSer and Assemblies
node. - Each PermissionSet node can contain any number of IPermission nodes
- Schema of IPermission nodes are defined by the .NET framework
- Each Assemblies node can contain any number of Assembly nodes.
- The CodeAccessSecurity/PolicyItem/Assemblies/Assembly node is different
than the Solution/Assemblies/Assembly node. - The Assembly node can contain any of the following attributes:
- Name
- Version
- PublicKeyBlob
0 comments:
Post a Comment