
Modifying Trust-Level Files
You can alter the policy files or create new ones with custom permission sets. For example, you can copy the contents of the Web_hightrust.config file and assign permission to make OLEDB connections by first adding the OleDbPermission class to the SecurityClasses section of the policy file, as shown in the following code example.
<SecurityClass Name="OleDbPermission"
Description="System.Data.OleDb.OleDbPermission, System.Data, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
You can then specify the parameters for the specified OleDbPermission, including restrictions for OLEDB connection strings. Next, you can specify which permission sets include the OleDbPermission security class by adding an IPermission element to the PermissionSet element with a name of ASP.NET in the trust-policy file. For example, the following code example specifies that the only allowed OLEDB connection will grant unrestricted access to the Catalog.mdb Access database.
<PermissionSet
class="NamedPermissionSet"
version="1"
Name="ASP.Net">
<IPermission
class="OleDbPermission"
version="1"
Unrestricted="true" />
</PermissionSet>
Some permissions, such as the OleDbPermission permission, allow you specify additional restrictions that narrow the access that is granted or denied. For example, the OleDbPermission permission allows you to grant access to make connections using the OLE DB .NET Framework Data Provider, but with restrictions on which OLEDB connection strings are allowed. The following code example specifies that the only allowed OLEDB connections to Access databases are allowed.
<IPermission class="OleDbPermission" version="1">
<add ConnectionString=
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\access_data\catalog.mdb""
KeyRestrictions=""data source=;user id=;password=;"
KeyRestrictionBehavior="AllowOnly"/>
</IPermission>
You can save your updated trust-policy file and put it in place of the current Web_hightrust.config file, or you can create a new trust-policy file and either specify that as the policy file for the High trust level, or create a new trust level as shown in the following code example.
<trustLevel name="HighCustom"
policyFile="web_highcustom.config"/>
In order to preserve the default settings, ASP.NET includes two copies of each file that contains trust-level settings. One copy is named with the file name extension .config, as shown in the configuration section earlier. The .config file contains the settings for each trust level used by the system. The second copy is named with the file name extension .config.default and contains the default settings for the related trust level. If the current trust-level settings have been modified and you want to restore the default settings, you can replace the contents of the .config file with the contents of the .config.default file.
For a more detailed description of managing a trust policy file, see "How To: Use Medium Trust in ASP.NET 2.0" at Patterns and Practices (PAG): Security Guidance for Applications.