Trust levels is associated with policy files through the <securityPolicy> configuration element. The <securityPolicy> element is only in the site-level configuration file (web. in config. you can add or remove the trust levels by adding the specified trust name and policy file entries in the configuration section. the default trust files are installed in the config directory that contains the aspnet_isapi.dll file directory. this is also machine. the Config configuration file exists, and the security policy file is stored at runtime.
FullTrust is a special case. because it is completely equivalent to having full trust, Asp. net host disease will not apply any additional policies on these applications. so,FullThe trust level is mapped to an internal handler, and ASP. Net does not add additional policies to their application domains for full-trust applications.
The following example shows the securityPolicy section of a configuration file mapped with trust levels to different policy files.
<system.web> <securityPolicy> <trustLevel name="Full" policyFile="internal"/> <trustLevel name="High" policyFile="web_hightrust.config"/> <trustLevel name="Medium" policyFile="web_mediumtrust.config"/> <trustLevel name="Low" policyFile="web_lowtrust.config"/> <trustLevel name="Minimal" policyFile="web_minimaltrust.config"/> </securityPolicy></system.web>
If you do not want applications to specify their own trust level, you can specify a <location> description and configureAllowOverrideThe property isFalse.You can do this on a server that stores multiple applications to limit the trust level of the application on it.
Modify trust-level file
======================
You can modify the policy file or create a new policy file and configure a custom permission set in it. For example, you can copy the content of the web_hightrust.config file, first in the policy fileSecurityclassesAdd an oledbpermission class to grant permissions to establish an oledb connection, 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 specify parameters for the specified oledbpermission class, including restrictions on oledb connection strings. Next, you can include the oledbpermission security class in the trust-policy file.PermissionsetAddIpermissionElement, with the specified nameASP. NET.For example, the following code example specifies that only the allowed oledb connection is granted unlimited permissions to access the database of catalog. MDB.
<PermissionSet class="NamedPermissionSet" version="1" Name="ASP.Net"> <IPermission class="OleDbPermission" version="1" Unrestricted="true" /></PermissionSet>
Some permissions, such as oledbpermission, allow you to specify additional restrictions to narrow down the permissions granted or obtained. For example,OledbpermissionPermission allows you to grant permissions to use ole db. NET framework data provider to establish a connection to access ole db, but the connection string of which oledb can be allowed. the following code example specifies the allowed oledb connection.
<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 the updated Trust-policy file and use it to replace the current web_hightrust.config file, or create a new trust-policy fileHighTrust level policy file, or use the following code example to create a new trust level.
<trustLevel name="HighCustom" policyFile="web_highcustom.config"/>
To save the default configuration, Asp. net contains two sets of files containing the trust-level configuration. A copy is taken. config extension name, just like the previous configuration section .. the config file contains configurations of every level used by the system. another copy is used. config. default is used as the suffix, which includes the default configuration of the relevant trust level. if the current trust-level configuration is modified and you want to restore the default configuration, you can use this set to overwrite it. content in the config file.
Translated from:
ASP. NET trust levels and policy files
Http://msdn.microsoft.com/en-us/library/wyts434y.aspx