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 類別的新執行個體。 |