TrustLevel 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
定义特定安全级别到指定策略文件的映射。 此类不能被继承。
public ref class TrustLevel sealed : System::Configuration::ConfigurationElement
public sealed class TrustLevel : System.Configuration.ConfigurationElement
type TrustLevel = class
inherit ConfigurationElement
Public NotInheritable Class TrustLevel
Inherits ConfigurationElement
- 继承
示例
下面的代码示例演示如何使用 TrustLevel 类型。
#region Using directives
using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.Web;
using System.Web.Configuration;
#endregion
namespace Samples.Aspnet.SystemWebConfiguration
{
class UsingTrustLevel
{
static void Main(string[] args)
{
try
{
// Display title.
Console.WriteLine("ASP.NET TrustLevel Info");
Console.WriteLine();
// Instantiate a new TrustLevel object.
TrustLevel TrustLevel1 =
new TrustLevel("myLevel1", "myLevel1.config");
// Get the Name of the TrustLevel object.
Console.WriteLine("Name: {0}", TrustLevel1.Name);
// Instantiate a new TrustLevel object.
TrustLevel TrustLevel2 =
new TrustLevel("myLevel2", "myLevel2.config");
// Get the PolicyFile of the TrustLevel object.
Console.WriteLine("PolicyFile: {0}", TrustLevel2.PolicyFile);
}
catch (Exception e)
{
// Unknown error.
Console.WriteLine(e.ToString());
}
// Display and wait.
Console.ReadLine();
}
}
}
Imports System.Collections.Generic
Imports System.Text
Imports System.Configuration
Imports System.Web
Imports System.Web.Configuration
Namespace Samples.Aspnet.SystemWebConfiguration
Class UsingTrustLevel
Public Shared Sub Main()
Try
' Display title.
Console.WriteLine("ASP.NET TrustLevel Info")
Console.WriteLine()
' Instantiate a new TrustLevel object.
Dim TrustLevel1 As TrustLevel = _
New TrustLevel("myLevel1", "myLevel1.config")
' Get the Name of the TrustLevel object.
Console.WriteLine("Name: {0}", TrustLevel1.Name)
' Instantiate a new TrustLevel object.
Dim TrustLevel2 As TrustLevel = _
New TrustLevel("myLevel2", "myLevel2.config")
' Get the PolicyFile of the TrustLevel object.
Console.WriteLine("PolicyFile: {0}", TrustLevel2.PolicyFile)
Catch e As Exception
' Unknown error.
Console.WriteLine(e.ToString())
End Try
' Display and wait.
Console.ReadLine()
End Sub
End Class
End Namespace
注解
可以通过创建自己的命名 TrustLevel 对象(该对象映射到 由 policyFile
属性指定的文件)来扩展 Web 应用程序的安全性。
构造函数
TrustLevel(String, String) |
创建一个基于提供的值进行初始化的 TrustLevel 类的实例,该实例定义特定安全级别到指定策略文件的映射。 |