HostProtectionAttribute.SecurityInfrastructure 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定值,表示是否公開安全性基礎結構。
public:
property bool SecurityInfrastructure { bool get(); void set(bool value); };
public bool SecurityInfrastructure { get; set; }
[System.Runtime.InteropServices.ComVisible(true)]
public bool SecurityInfrastructure { get; set; }
member this.SecurityInfrastructure : bool with get, set
[<System.Runtime.InteropServices.ComVisible(true)>]
member this.SecurityInfrastructure : bool with get, set
Public Property SecurityInfrastructure As Boolean
屬性值
如果公開安全性基礎結構,則為 true
,否則為 false
。 預設為 false
。
- 屬性
範例
下列程式代碼範例說明屬性搭配 SecurityInfrastructure 屬性的使用HostProtectionAttribute方式。 此範例是針對 類別提供的較大範例的 HostProtectionAttribute 一部分。
// Use the enumeration flags to indicate that this method exposes shared state,
// self-affecting threading and the security infrastructure.
// ApplyIdentity sets the current identity.
[HostProtection(SharedState=true,SelfAffectingThreading=true,
SecurityInfrastructure=true)]
static int ApplyIdentity()
{
array<String^>^roles = {"User"};
try
{
AppDomain^ mAD = AppDomain::CurrentDomain;
GenericPrincipal^ mGenPr = gcnew GenericPrincipal( WindowsIdentity::GetCurrent(),roles );
mAD->SetPrincipalPolicy( PrincipalPolicy::WindowsPrincipal );
mAD->SetThreadPrincipal( mGenPr );
return Success;
}
catch ( Exception^ e )
{
Exit( e->ToString(), 5 );
}
return 0;
}
// Use the enumeration flags to indicate that this method exposes shared
// state, self-affecting threading, and the security infrastructure.
[HostProtectionAttribute(SharedState=true, SelfAffectingThreading=true,
SecurityInfrastructure=true)]
// ApplyIdentity sets the current identity.
private static int ApplyIdentity()
{
string[] roles = {"User"};
try
{
AppDomain mAD = AppDomain.CurrentDomain;
GenericPrincipal mGenPr =
new GenericPrincipal(WindowsIdentity.GetCurrent(), roles);
mAD.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
mAD.SetThreadPrincipal(mGenPr);
return Success;
}
catch (Exception e)
{
Exit(e.ToString(), 5);
}
return 0;
}
' Use the enumeration flags to indicate that this method exposes shared
' state, self-affecting threading, and the security infrastructure.
<HostProtectionAttribute(SharedState := True, _
SelfAffectingThreading := True, _
SecurityInfrastructure := True)> _
Private Shared Function ApplyIdentity() As Integer
' ApplyIdentity sets the current identity.
Dim roles(1) As String
Try
Dim mAD As AppDomain = AppDomain.CurrentDomain
Dim mGenPr As _
New GenericPrincipal(WindowsIdentity.GetCurrent(), roles)
mAD.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal)
mAD.SetThreadPrincipal(mGenPr)
Return Success
Catch e As Exception
[Exit](e.ToString(), 5)
End Try
Return 0
End Function 'ApplyIdentity
備註
使用 WindowsIdentity 物件來模擬用戶是公開安全性基礎結構的範例。