TrustSection 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
配置应用于应用程序的代码访问安全级别。 此类不能被继承。
public ref class TrustSection sealed : System::Configuration::ConfigurationSection
public sealed class TrustSection : System.Configuration.ConfigurationSection
type TrustSection = class
inherit ConfigurationSection
Public NotInheritable Class TrustSection
Inherits ConfigurationSection
- 继承
示例
本部分提供两个代码示例。 第一个演示如何以声明方式指定类的 TrustSection 多个属性的值。 第二个演示了如何使用类型 TrustSection 。
以下配置文件示例演示如何以声明方式指定类的 TrustSection 多个属性的值。
<system.web>
<trust level="Full" originUrl=""/>
</system.web>
下面的代码示例演示如何使用该 TrustSection 类型。
#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 UsingTrustSection
{
static void Main(string[] args)
{
try
{
// Set the path of the config file.
string configPath = "";
// Get the Web application configuration object.
Configuration config = WebConfigurationManager.OpenWebConfiguration(configPath);
// Get the section related object.
TrustSection configSection = (TrustSection)config.GetSection("system.web/trust");
// Display title and info.
Console.WriteLine("ASP.NET Configuration Info");
Console.WriteLine();
// Display Config details.
Console.WriteLine("File Path: {0}", config.FilePath);
Console.WriteLine("Section Path: {0}", configSection.SectionInformation.Name);
// Display Level property
Console.WriteLine("Level: {0}", configSection.Level);
// Set Level property
configSection.Level = "Full";
// Display OriginUrl property
Console.WriteLine("Origin Url: {0}", configSection.OriginUrl);
// Set OriginUrl property
configSection.OriginUrl = "";
// Update if not locked.
if (!configSection.SectionInformation.IsLocked)
{
config.Save();
Console.WriteLine("** Configuration updated.");
}
else
{
Console.WriteLine("** Could not update, section is locked.");
}
}
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 UsingTrustSection
Public Shared Sub Main()
Try
' Set the path of the config file.
Dim configPath As String = ""
' Get the Web application configuration object.
Dim config As System.Configuration.Configuration = _
System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(configPath)
' Get the section related object.
Dim configSection As System.Web.Configuration.TrustSection = _
CType(config.GetSection("system.web/trust"), _
System.Web.Configuration.TrustSection)
' Display title and info.
Console.WriteLine("ASP.NET Configuration Info")
Console.WriteLine()
' Display Config details.
Console.WriteLine("File Path: {0}", config.FilePath)
Console.WriteLine("Section Path: {0}", configSection.SectionInformation.Name)
' Display Level property.
Console.WriteLine("Level: {0}", configSection.Level)
' Set Level property.
configSection.Level = "High"
' Display OriginUrl property.
Console.WriteLine("Origin Url: {0}", configSection.OriginUrl)
' Set OriginUrl property.
configSection.OriginUrl = ""
' Update if not locked.
If Not configSection.SectionInformation.IsLocked Then
config.Save()
Console.WriteLine("** Configuration updated.")
Else
Console.WriteLine("** Could not update, section is locked.")
End If
Catch e As Exception
' Unknown error.
Console.WriteLine(e.ToString())
End Try
' Display and wait
Console.ReadLine()
End Sub
End Class
End Namespace
注解
该 TrustSection 类允许以编程方式访问和修改配置文件 <trust>
部分。 本 <trust>
部分配置用于运行特定应用程序的代码访问安全权限集。 本部分可以在计算机、站点和应用程序级别声明。
构造函数
TrustSection() |
使用默认设置初始化 TrustSection 类的新实例。 |