XmlSecureResolver 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 XmlSecureResolver 類別的新執行個體。
多載
XmlSecureResolver(XmlResolver, PermissionSet) |
指定 XmlResolver 和 PermissionSet 來初始化 XmlSecureResolver 類別的新執行個體。 |
XmlSecureResolver(XmlResolver, Evidence) |
指定 XmlResolver 和 Evidence 來初始化 XmlSecureResolver 類別的新執行個體。 |
XmlSecureResolver(XmlResolver, String) |
使用提供的 XmlResolver 和 URL,初始化 XmlSecureResolver 類別的新執行個體。 |
備註
這三個建構函式提供三種類型的存取限制:
建 XmlSecureResolver(XmlResolver, String) 構函式會使用 URL 來限制存取。
建構函式 XmlSecureResolver(XmlResolver, PermissionSet) 會使用許可權集合來限制存取。
建構函式 XmlSecureResolver(XmlResolver, Evidence) 會使用辨識項來限制存取。
如需這些限制類型的範例,請參閱建構函式參考主題。
XmlSecureResolver(XmlResolver, PermissionSet)
指定 XmlResolver 和 PermissionSet 來初始化 XmlSecureResolver 類別的新執行個體。
public:
XmlSecureResolver(System::Xml::XmlResolver ^ resolver, System::Security::PermissionSet ^ permissionSet);
public XmlSecureResolver (System.Xml.XmlResolver resolver, System.Security.PermissionSet permissionSet);
new System.Xml.XmlSecureResolver : System.Xml.XmlResolver * System.Security.PermissionSet -> System.Xml.XmlSecureResolver
Public Sub New (resolver As XmlResolver, permissionSet As PermissionSet)
參數
- resolver
- XmlResolver
XmlSecureResolver 所包裝的 XML 解析程式。
- permissionSet
- PermissionSet
要套用至底層 XmlResolver 的權限集。 XmlSecureResolver 會在呼叫底層 XML 解析程式上的 GetEntity(Uri, String, Type) 方法之前先呼叫權限集上的 PermitOnly() 方法。
範例
下列範例會 XmlSecureResolver 使用自訂的許可權集合來建構 物件。
Object^ GetFile( String^ fileURL, XmlResolver^ resolver )
{
// Generate the default PermissionSet using the file URL.
Evidence^ evidence = XmlSecureResolver::CreateEvidenceForUrl( fileURL );
PermissionSet^ myPermissions = SecurityManager::ResolvePolicy( evidence );
// Modify the PermissionSet to only allow access to http://www.contoso.com.
// Create a WebPermission which only allows access to http://www.contoso.com.
WebPermission^ myWebPermission = gcnew WebPermission(
NetworkAccess::Connect,"http://www.contoso.com" );
// Replace the existing WebPermission in myPermissions with the updated WebPermission.
myPermissions->SetPermission( myWebPermission );
// Use the modified PermissionSet to construct the XmlSecureResolver.
XmlSecureResolver^ sResolver = gcnew XmlSecureResolver( resolver,myPermissions );
// Get the object.
Uri^ fullUri = sResolver->ResolveUri( nullptr, fileURL );
return sResolver->GetEntity( fullUri, nullptr, nullptr );
}
public static Object GetFile (String fileURL, XmlResolver resolver) {
// Generate the default PermissionSet using the file URL.
Evidence evidence = XmlSecureResolver.CreateEvidenceForUrl(fileURL);
PermissionSet myPermissions = SecurityManager.ResolvePolicy(evidence);
// Modify the PermissionSet to only allow access to http://www.contoso.com.
// Create a WebPermission which only allows access to http://www.contoso.com.
WebPermission myWebPermission = new WebPermission(NetworkAccess.Connect, "http://www.contoso.com");
// Replace the existing WebPermission in myPermissions with the updated WebPermission.
myPermissions.SetPermission(myWebPermission);
// Use the modified PermissionSet to construct the XmlSecureResolver.
XmlSecureResolver sResolver = new XmlSecureResolver(resolver, myPermissions);
// Get the object.
Uri fullUri = sResolver.ResolveUri(null, fileURL);
return sResolver.GetEntity(fullUri, null, null);
}
public shared function GetFile (fileURL as String , resolver as XmlResolver) as Object
' Generate the default PermissionSet using the file URL.
Dim evidence as Evidence = XmlSecureResolver.CreateEvidenceForUrl(fileURL)
Dim myPermissions as PermissionSet = SecurityManager.ResolvePolicy(evidence)
' Modify the PermissionSet to only allow access to http://www.contoso.com.
' Create a WebPermission that only allows access to http://www.contoso.com.
Dim myWebPermission as WebPermission = new WebPermission(NetworkAccess.Connect, "http://www.contoso.com")
' Replace the existing WebPermission in myPermissions with the updated WebPermission.
myPermissions.SetPermission(myWebPermission)
' Use the modified PermissionSet to construct the XmlSecureResolver.
Dim sResolver as XmlSecureResolver = new XmlSecureResolver(resolver, myPermissions)
' Get the object.
Dim fullUri as Uri = sResolver.ResolveUri(nothing, fileURL)
return sResolver.GetEntity(fullUri, nothing, nothing)
end function
另請參閱
適用於
XmlSecureResolver(XmlResolver, Evidence)
指定 XmlResolver 和 Evidence 來初始化 XmlSecureResolver 類別的新執行個體。
public:
XmlSecureResolver(System::Xml::XmlResolver ^ resolver, System::Security::Policy::Evidence ^ evidence);
public XmlSecureResolver (System.Xml.XmlResolver resolver, System.Security.Policy.Evidence evidence);
new System.Xml.XmlSecureResolver : System.Xml.XmlResolver * System.Security.Policy.Evidence -> System.Xml.XmlSecureResolver
Public Sub New (resolver As XmlResolver, evidence As Evidence)
參數
- resolver
- XmlResolver
XmlSecureResolver 所包裝的 XML 解析程式。
- evidence
- Evidence
用來建立 PermissionSet 且將套用至底層 XmlResolver 的辨識項。 XmlSecureResolver 會在呼叫底層 XmlResolver 上的 GetEntity(Uri, String, Type) 之前先呼叫已建立之 PermissionSet 上的 PermitOnly() 方法。
備註
以下是一些可能案例,以及每個案例所提供的辨識項類型:
如果您正在完全信任的環境中工作,請使用元件來建立辨識項:
Evidence myEvidence = this.GetType().Assembly.Evidence; XmlSecureResolver myResolver; myResolver = new XmlSecureResolver(new XmlUrlResolver(), myEvidence);
Dim myEvidence As Evidence = Me.GetType().Assembly.Evidence Dim myResolver As XmlSecureResolver myResolver = New XmlSecureResolver(New XmlUrlResolver(), myEvidence)
如果您是在半信任的環境中工作,您有來自外部來源的程式碼或資料,而且您知道外部來源的來源,而且具有可驗證的 URI,請使用 URI 來建立辨識項:
Evidence myEvidence = XmlSecureResolver.CreateEvidenceForUrl(sourceURI); XmlSecureResolver myResolver = new XmlSecureResolver(new XmlUrlResolver(), myEvidence);
Dim myEvidence As Evidence = XmlSecureResolver.CreateEvidenceForUrl(sourceURI) Dim myResolver As New XmlSecureResolver(New XmlUrlResolver(), myEvidence)
如果您正在半信任的環境中工作,而且您有來自外部來源的程式碼或資料,但您不知道外部來源的來源,無論是:
將
evidence
參數設定為null
。 這可以拒絕對資源的任何存取。-或-
如果應用程式需要資源的某些存取權,請要求呼叫端的辨識項。
適用於
XmlSecureResolver(XmlResolver, String)
使用提供的 XmlResolver 和 URL,初始化 XmlSecureResolver 類別的新執行個體。
public:
XmlSecureResolver(System::Xml::XmlResolver ^ resolver, System::String ^ securityUrl);
public XmlSecureResolver (System.Xml.XmlResolver resolver, string? securityUrl);
public XmlSecureResolver (System.Xml.XmlResolver resolver, string securityUrl);
new System.Xml.XmlSecureResolver : System.Xml.XmlResolver * string -> System.Xml.XmlSecureResolver
Public Sub New (resolver As XmlResolver, securityUrl As String)
參數
- resolver
- XmlResolver
XmlSecureResolver 所包裝的 XML 解析程式。
- securityUrl
- String
用來建立將套用至基礎 XmlResolver 的 PermissionSet 之 URL。 XmlSecureResolver 會先呼叫已建立之 PermissionSet 上的 PermitOnly(),然後才呼叫基礎 XmlResolver 上的 GetEntity(Uri, String, Type)。
範例
此範例會使用 建 XmlSecureResolver(XmlResolver, String) 構函式來建立 XmlSecureResolver 只允許存取本機內部網路網站的物件。
XmlSecureResolver myResolver = new XmlSecureResolver(new XmlUrlResolver(), "http://myLocalSite/");
Dim myResolver As New XmlSecureResolver(New XmlUrlResolver(), "http://myLocalSite/")
備註
重要
在 .NET Framework Common Language Runtime (CLR) 上執行的程式碼,以及在 Microsoft SQL Server 2005 內整合之 CLR 上執行的程式碼,安全性基礎結構有差異。 這可能會導致在SQL Server整合式 CLR 上使用時,針對.NET Framework CLR 開發的程式碼以不同的方式運作。 當您有以 URL (為基礎的辨識項時,當您使用 CreateEvidenceForUrl 方法或 XmlSecureResolver(XmlResolver, String) 建構函式) 時,其中一個差異 XmlSecureResolver 會影響 類別。 SQL Server整合式 CLR 的原則解決機制不會使用 Url 或 Zone 資訊。 相反地,它會根據伺服器載入元件時新增的 GUID 來授與許可權。 當您在 XmlSecureResolver SQL Server整合式 CLR 中使用 時,請使用指定的 PermissionSet 直接提供任何必要辨識項。