ResourcePermissionBase 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
警告
Code Access Security is not supported or honored by the runtime.
允許的程式碼存取安全性權限控制。
public ref class ResourcePermissionBase abstract : System::Security::CodeAccessPermission, System::Security::Permissions::IUnrestrictedPermission
public abstract class ResourcePermissionBase : System.Security.CodeAccessPermission, System.Security.Permissions.IUnrestrictedPermission
[System.Obsolete("Code Access Security is not supported or honored by the runtime.", DiagnosticId="SYSLIB0003", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public abstract class ResourcePermissionBase : System.Security.CodeAccessPermission, System.Security.Permissions.IUnrestrictedPermission
[System.Serializable]
public abstract class ResourcePermissionBase : System.Security.CodeAccessPermission, System.Security.Permissions.IUnrestrictedPermission
type ResourcePermissionBase = class
inherit CodeAccessPermission
interface IUnrestrictedPermission
[<System.Obsolete("Code Access Security is not supported or honored by the runtime.", DiagnosticId="SYSLIB0003", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
type ResourcePermissionBase = class
inherit CodeAccessPermission
interface IUnrestrictedPermission
[<System.Serializable>]
type ResourcePermissionBase = class
inherit CodeAccessPermission
interface IUnrestrictedPermission
Public MustInherit Class ResourcePermissionBase
Inherits CodeAccessPermission
Implements IUnrestrictedPermission
- 繼承
- 衍生
- 屬性
- 實作
範例
下列範例繼承自 ResourcePermissionBase 類別。 實作 4 種建構函式。 此範例也提供稱為 MailslotPermissionEntry
的類別實作。 然後,屬性 PermissionAccessType 會私下設定為 的類型 MailslotPermissionEntry
。 屬性 TagNames 會私下設定為 「Name」 和 「Machine」。
#using <System.dll>
using namespace System;
using namespace System::Security::Permissions;
using namespace System::Collections;
[Flags]
public enum class MailslotPermissionAccess
{
None = 0,
Send = 1 << 1,
Receive = 1 << 2 | MailslotPermissionAccess::Send
};
[Serializable]
public ref class MailslotPermissionEntry
{
private:
String^ name;
String^ machineName;
MailslotPermissionAccess permissionAccess;
internal:
MailslotPermissionEntry( ResourcePermissionBaseEntry^ baseEntry )
{
this->permissionAccess = (MailslotPermissionAccess)baseEntry->PermissionAccess;
this->name = baseEntry->PermissionAccessPath[ 0 ]->ToString();
this->machineName = baseEntry->PermissionAccessPath[ 1 ]->ToString();
}
ResourcePermissionBaseEntry^ GetBaseEntry()
{
array<String^>^newStrings = {this->Name,this->MachineName};
ResourcePermissionBaseEntry^ baseEntry = gcnew ResourcePermissionBaseEntry( (int)(this->PermissionAccess),newStrings );
return baseEntry;
}
public:
MailslotPermissionEntry( MailslotPermissionAccess permissionAccess, String^ name, String^ machineName )
{
this->permissionAccess = permissionAccess;
this->name = name;
this->machineName = machineName;
}
property String^ Name
{
String^ get()
{
return this->name;
}
}
property String^ MachineName
{
String^ get()
{
return this->machineName;
}
}
property MailslotPermissionAccess PermissionAccess
{
MailslotPermissionAccess get()
{
return this->permissionAccess;
}
}
};
[Serializable]
public ref class MailslotPermission: public ResourcePermissionBase
{
private:
ArrayList^ innerCollection;
void SetNames()
{
this->PermissionAccessType = MailslotPermissionAccess::typeid;
array<String^>^newStrings = {"Name","Machine"};
this->TagNames = newStrings;
}
internal:
void AddPermissionAccess( MailslotPermissionEntry^ entry )
{
ResourcePermissionBase::AddPermissionAccess( entry->GetBaseEntry() );
}
void Clear()
{
ResourcePermissionBase::Clear();
}
void RemovePermissionAccess( MailslotPermissionEntry^ entry )
{
ResourcePermissionBase::RemovePermissionAccess( entry->GetBaseEntry() );
}
public:
MailslotPermission()
{
SetNames();
}
MailslotPermission( PermissionState state )
: ResourcePermissionBase( state )
{
SetNames();
}
MailslotPermission( MailslotPermissionAccess permissionAccess, String^ name, String^ machineName )
{
SetNames();
this->AddPermissionAccess( gcnew MailslotPermissionEntry( permissionAccess,name,machineName ) );
}
MailslotPermission( array<MailslotPermissionEntry^>^permissionAccessEntries )
{
SetNames();
if ( permissionAccessEntries == nullptr )
throw gcnew ArgumentNullException( "permissionAccessEntries" );
for ( int index = 0; index < permissionAccessEntries->Length; ++index )
this->AddPermissionAccess( permissionAccessEntries[ index ] );
}
property ArrayList^ PermissionEntries
{
ArrayList^ get()
{
if ( this->innerCollection == nullptr )
this->innerCollection = gcnew ArrayList;
this->innerCollection->InsertRange( 0, safe_cast<ICollection^>(ResourcePermissionBase::GetPermissionEntries()) );
return this->innerCollection;
}
}
};
using System;
using System.Security.Permissions;
using System.Collections;
[Serializable()]
public class MailslotPermission: ResourcePermissionBase
{
private ArrayList innerCollection;
public MailslotPermission()
{
SetNames();
}
public MailslotPermission(PermissionState state):base(state)
{
SetNames();
}
public MailslotPermission(MailslotPermissionAccess permissionAccess, string name, string machineName)
{
SetNames();
this.AddPermissionAccess(new MailslotPermissionEntry(permissionAccess, name, machineName));
}
public MailslotPermission(MailslotPermissionEntry[] permissionAccessEntries)
{
SetNames();
if (permissionAccessEntries == null)
throw new ArgumentNullException("permissionAccessEntries");
for (int index = 0; index < permissionAccessEntries.Length; ++index)
this.AddPermissionAccess(permissionAccessEntries[index]);
}
public ArrayList PermissionEntries
{
get
{
if (this.innerCollection == null)
this.innerCollection = new ArrayList();
this.innerCollection.InsertRange(0,base.GetPermissionEntries());
return this.innerCollection;
}
}
internal void AddPermissionAccess(MailslotPermissionEntry entry)
{
base.AddPermissionAccess(entry.GetBaseEntry());
}
internal new void Clear()
{
base.Clear();
}
internal void RemovePermissionAccess(MailslotPermissionEntry entry)
{
base.RemovePermissionAccess(entry.GetBaseEntry());
}
private void SetNames()
{
this.PermissionAccessType = typeof(MailslotPermissionAccess);
this.TagNames = new string[]{"Name","Machine"};
}
}
[Flags]
public enum MailslotPermissionAccess
{
None = 0,
Send = 1 << 1,
Receive = 1 << 2 | Send,
}
[Serializable()]
public class MailslotPermissionEntry
{
private string name;
private string machineName;
private MailslotPermissionAccess permissionAccess;
public MailslotPermissionEntry(MailslotPermissionAccess permissionAccess, string name, string machineName)
{
this.permissionAccess = permissionAccess;
this.name = name;
this.machineName = machineName;
}
internal MailslotPermissionEntry(ResourcePermissionBaseEntry baseEntry)
{
this.permissionAccess = (MailslotPermissionAccess)baseEntry.PermissionAccess;
this.name = baseEntry.PermissionAccessPath[0];
this.machineName = baseEntry.PermissionAccessPath[1];
}
public string Name
{
get
{
return this.name;
}
}
public string MachineName
{
get
{
return this.machineName;
}
}
public MailslotPermissionAccess PermissionAccess
{
get
{
return this.permissionAccess;
}
}
internal ResourcePermissionBaseEntry GetBaseEntry()
{
ResourcePermissionBaseEntry baseEntry = new ResourcePermissionBaseEntry((int)this.PermissionAccess, new string[] {this.Name,this.MachineName});
return baseEntry;
}
}
Imports System.Security.Permissions
Imports System.Collections
<Serializable()> Public Class MailslotPermission
Inherits ResourcePermissionBase
Private innerCollection As ArrayList
Public Sub New()
SetNames()
End Sub
Public Sub New(ByVal state As PermissionState)
MyBase.New(state)
SetNames()
End Sub
Public Sub New(ByVal permissionAccess As MailslotPermissionAccess, ByVal name As String, ByVal machineName1 As String)
SetNames()
Me.AddPermissionAccess(New MailslotPermissionEntry(permissionAccess, name, machineName1))
End Sub
Public Sub New(ByVal permissionAccessEntries() As MailslotPermissionEntry)
SetNames()
If permissionAccessEntries Is Nothing Then
Throw New ArgumentNullException("permissionAccessEntries")
End If
Dim index As Integer
While index < permissionAccessEntries.Length
Me.AddPermissionAccess(permissionAccessEntries(index))
End While
End Sub
Public ReadOnly Property PermissionEntries() As ArrayList
Get
If Me.innerCollection Is Nothing Then
Me.innerCollection = New ArrayList()
End If
Me.innerCollection.InsertRange(0, MyBase.GetPermissionEntries())
Return Me.innerCollection
End Get
End Property
Friend Overloads Sub AddPermissionAccess(ByVal entry As MailslotPermissionEntry)
MyBase.AddPermissionAccess(entry.GetBaseEntry())
End Sub
Friend Shadows Sub Clear()
MyBase.Clear()
End Sub
Friend Overloads Sub RemovePermissionAccess(ByVal entry As MailslotPermissionEntry)
MyBase.RemovePermissionAccess(entry.GetBaseEntry())
End Sub
Private Sub SetNames()
Me.PermissionAccessType = GetType(MailslotPermissionAccess)
Me.TagNames = New String() {"Name", "Machine"}
End Sub
End Class
<Flags()> Public Enum MailslotPermissionAccess
None = 0
Send = 2
Receive = 4 Or Send
End Enum 'MailslotPermissionAccess
<Serializable()> Public Class MailslotPermissionEntry
Private nameVar As String
Private machineNameVar As String
Private permissionAccessVar As MailslotPermissionAccess
Public Sub New(ByVal permissionAccess As MailslotPermissionAccess, ByVal name As String, ByVal machineName1 As String)
Me.permissionAccessVar = permissionAccess
Me.nameVar = name
Me.machineNameVar = machineName1
End Sub
Friend Sub New(ByVal baseEntry As ResourcePermissionBaseEntry)
Me.permissionAccessVar = CType(baseEntry.PermissionAccess, MailslotPermissionAccess)
Me.nameVar = baseEntry.PermissionAccessPath(0)
Me.machineNameVar = baseEntry.PermissionAccessPath(1)
End Sub
Public ReadOnly Property Name() As String
Get
Return Me.nameVar
End Get
End Property
Public ReadOnly Property MachineName() As String
Get
Return Me.machineNameVar
End Get
End Property
Public ReadOnly Property PermissionAccess() As MailslotPermissionAccess
Get
Return Me.permissionAccessVar
End Get
End Property
Friend Function GetBaseEntry() As ResourcePermissionBaseEntry
Dim baseEntry As New ResourcePermissionBaseEntry(CInt(Me.PermissionAccess), New String() {Me.Name, Me.MachineName})
Return baseEntry
End Function 'GetBaseEntry
End Class
備註
警告
程式碼存取安全性 (CAS) 在所有版本的 .NET Framework 和 .NET 中已被取代。 使用 CAS 相關 API 時,最新版本的 .NET 不會接受 CAS 批註,並產生錯誤。 開發人員應該尋求替代方式來完成安全性工作。
注意
類別 ResourcePermissionBase 會使用序數排序規則比較字串,並忽略所比較字串的大小寫。
給實施者的注意事項
當您繼承自 ResourcePermissionBase 時,必須至少提供三個建構函式、設定兩個屬性,並提供第三個屬性。 必要的建構函式包括:無參數建構函式、採用 PermissionState 做為參數的建構函式,以及接受屬性值的所需數目。 需要設定的屬性為 PermissionAccessType 和 TagNames 。 需要的第三個屬性是傳回許可權專案的屬性。 如需這個類別實作的範例,請參閱 PerformanceCounterPermission 。 在 PerformanceCounterPermission 中,屬性 TagNames 會私下設定為 「Machine」 和 「Category」, PermissionAccessType 此屬性會私下設定為 的類型 PerformanceCounterPermissionAccess ,而 PermissionEntries 屬性會傳回許可權專案。
建構函式
ResourcePermissionBase() |
初始化 ResourcePermissionBase 類別的新執行個體。 |
ResourcePermissionBase(PermissionState) |
使用建立資源時的指定存取權等級,初始化 ResourcePermissionBase 類別的新執行個體。 |
欄位
Any |
指定用來表示任何萬用字元 (Wildcard Character) 的字元。 |
Local |
指定用來表示區域參考的字元。 |
屬性
PermissionAccessType |
取得或設定一個列舉值,以描述對資源您所授與的存取權類型。 |
TagNames |
取得或設定一個字串陣列,以辨識您要保護的資源。 |
方法
AddPermissionAccess(ResourcePermissionBaseEntry) |
將使用權限項目加入至使用權限。 |
Assert() |
宣告即使堆疊中較高層的呼叫端未獲得資源存取權限,呼叫程式碼仍可透過呼叫這個方法的程式碼要求權限,來存取受保護的資源。 使用 Assert() 會造成安全性問題。 (繼承來源 CodeAccessPermission) |
Clear() |
清除已加入的使用權限項目中的使用權限。 |
Copy() |
建立並傳回目前使用權限物件的相同複本。 |
Demand() |
如果在呼叫堆疊中較高的所有呼叫端都尚未被授與由目前執行個體所指定之權限,則會在執行階段強制執行 SecurityException。 (繼承來源 CodeAccessPermission) |
Deny() |
已過時。
已過時。
防止呼叫堆疊中較高的呼叫端,使用程式碼呼叫此方法來存取目前執行個體所指定的資源。 (繼承來源 CodeAccessPermission) |
Equals(Object) |
判斷指定的 CodeAccessPermission 物件是否等於目前的 CodeAccessPermission。 (繼承來源 CodeAccessPermission) |
FromXml(SecurityElement) |
透過 XML 編碼,重新建構具有指定狀態的安全性物件。 |
GetHashCode() |
取得 CodeAccessPermission 物件的雜湊碼,其適合用於雜湊表這類的雜湊演算法和資料結構。 (繼承來源 CodeAccessPermission) |
GetPermissionEntries() |
傳回已加入至這個使用權限的 ResourcePermissionBaseEntry 物件陣列。 |
GetType() |
取得目前執行個體的 Type。 (繼承來源 Object) |
Intersect(IPermission) |
建立並傳回目前使用權限物件和目標使用權限物件交集的使用權限物件。 |
IsSubsetOf(IPermission) |
判斷目前使用權限物件是否為指定使用權限的子集。 |
IsUnrestricted() |
取得值,表示使用權限是否不受限制。 |
MemberwiseClone() |
建立目前 Object 的淺層複製。 (繼承來源 Object) |
PermitOnly() |
防止呼叫堆疊中較高的呼叫端,使用程式碼呼叫此方法來存取目前執行個體所指定之資源以外的所有資源。 (繼承來源 CodeAccessPermission) |
RemovePermissionAccess(ResourcePermissionBaseEntry) |
從使用權限中移除使用權限項目。 |
ToString() |
建立並傳回目前權限物件的字串表示。 (繼承來源 CodeAccessPermission) |
ToXml() |
建立並傳回安全性物件的 XML 編碼方式和目前狀態。 |
Union(IPermission) |
建立將目前使用權限物件和目標使用權限物件相結合的使用權限物件。 |