共用方式為


X509CertificateRecipientClientCredential.SetScopedCertificate 方法

定義

從存放區中設定憑證,並將它儲存在依設定範圍之 URL 建立索引的集合中。

多載

SetScopedCertificate(String, StoreLocation, StoreName, Uri)

依據主體名稱、憑證存放區位置和憑證存放區名稱設定憑證,並將它儲存在要用來做為設定範圍之 URL 的集合中。

SetScopedCertificate(StoreLocation, StoreName, X509FindType, Object, Uri)

依據憑證存放區位置、憑證存放區名稱、X.509 搜尋類型和要搜尋的值來設定憑證,並將它儲存在要用來做為設定範圍之 URL 的集合中。

SetScopedCertificate(String, StoreLocation, StoreName, Uri)

來源:
X509CertificateRecipientClientCredential.cs
來源:
X509CertificateRecipientClientCredential.cs
來源:
X509CertificateRecipientClientCredential.cs

依據主體名稱、憑證存放區位置和憑證存放區名稱設定憑證,並將它儲存在要用來做為設定範圍之 URL 的集合中。

public:
 void SetScopedCertificate(System::String ^ subjectName, System::Security::Cryptography::X509Certificates::StoreLocation storeLocation, System::Security::Cryptography::X509Certificates::StoreName storeName, Uri ^ targetService);
public void SetScopedCertificate (string subjectName, System.Security.Cryptography.X509Certificates.StoreLocation storeLocation, System.Security.Cryptography.X509Certificates.StoreName storeName, Uri targetService);
member this.SetScopedCertificate : string * System.Security.Cryptography.X509Certificates.StoreLocation * System.Security.Cryptography.X509Certificates.StoreName * Uri -> unit
Public Sub SetScopedCertificate (subjectName As String, storeLocation As StoreLocation, storeName As StoreName, targetService As Uri)

參數

subjectName
String

完整主體名稱。

storeLocation
StoreLocation

服務用來取得服務憑證之憑證存放區的位置。

storeName
StoreName

要開啟的 X.509 憑證存放區名稱。

targetService
Uri

設定範圍的 URL。

例外狀況

subjectNametargetServicenull

已嘗試設定認證何時是唯讀的。

範例

這段程式碼將示範如何呼叫這個方法。

public void snippet25(CalculatorClient cc)
{
    X509CertificateRecipientClientCredential rcc = cc.ClientCredentials.ServiceCertificate;
    rcc.SetScopedCertificate("http://fabrikam.com/sts",
                             StoreLocation.CurrentUser,
                             StoreName.TrustedPeople,
                             new Uri("http://fabrikam.com"));
}

備註

storeLocation 的值包含在 StoreLocation 列舉型別中:

  • LocalMachine:指派給本機電腦的憑證存放區。

  • CurrentUser:目前使用者所使用的憑證存放區 (預設) 。

如果應用程式是在系統帳戶下執行,則憑證通常位於 LocalMachine。 如果應用程式是在使用者帳戶下執行,則憑證通常位於 CurrentUser

storeName 的值包含在 StoreName 列舉型別中。

適用於

SetScopedCertificate(StoreLocation, StoreName, X509FindType, Object, Uri)

來源:
X509CertificateRecipientClientCredential.cs
來源:
X509CertificateRecipientClientCredential.cs
來源:
X509CertificateRecipientClientCredential.cs

依據憑證存放區位置、憑證存放區名稱、X.509 搜尋類型和要搜尋的值來設定憑證,並將它儲存在要用來做為設定範圍之 URL 的集合中。

public:
 void SetScopedCertificate(System::Security::Cryptography::X509Certificates::StoreLocation storeLocation, System::Security::Cryptography::X509Certificates::StoreName storeName, System::Security::Cryptography::X509Certificates::X509FindType findType, System::Object ^ findValue, Uri ^ targetService);
public void SetScopedCertificate (System.Security.Cryptography.X509Certificates.StoreLocation storeLocation, System.Security.Cryptography.X509Certificates.StoreName storeName, System.Security.Cryptography.X509Certificates.X509FindType findType, object findValue, Uri targetService);
member this.SetScopedCertificate : System.Security.Cryptography.X509Certificates.StoreLocation * System.Security.Cryptography.X509Certificates.StoreName * System.Security.Cryptography.X509Certificates.X509FindType * obj * Uri -> unit
Public Sub SetScopedCertificate (storeLocation As StoreLocation, storeName As StoreName, findType As X509FindType, findValue As Object, targetService As Uri)

參數

storeLocation
StoreLocation

服務用來取得服務憑證之憑證存放區的位置。

storeName
StoreName

要開啟的 X.509 憑證存放區名稱。

findType
X509FindType

要執行之 X.509 搜尋的類型。

findValue
Object

要在 X.509 憑證存放區內搜尋的值。

targetService
Uri

設定範圍的 URL。

例外狀況

findValuetargetServicenull

已嘗試設定認證何時是唯讀的。

範例

這段程式碼將示範如何呼叫這個方法。

public void snippet20(CalculatorClient client)
{
    X509CertificateRecipientClientCredential rcc = client.ClientCredentials.ServiceCertificate;
    rcc.SetScopedCertificate(StoreLocation.CurrentUser,
                             StoreName.TrustedPeople,
                             X509FindType.FindBySubjectName,
                             "FabrikamSTS",
                             new Uri("http://fabrikam.com/sts"));
}
rcc.SetScopedCertificate(StoreLocation.CurrentUser, _
            StoreName.TrustedPeople, _
            X509FindType.FindBySubjectName, _
            "FabrikamSTS", _
            New Uri("http://fabrikam.com/sts"))

備註

storeLocation 的值包含在 StoreLocation 列舉型別中:

  • LocalMachine:指派給本機電腦的憑證存放區。

  • CurrentUser:目前使用者所使用的憑證存放區 (預設) 。

如果應用程式是在系統帳戶下執行,則憑證通常位於 LocalMachine。 如果應用程式是在使用者帳戶下執行,則憑證通常位於 CurrentUser

storeName 的值包含在 StoreName 列舉型別中。

findType 的值包含在 X509FindType 列舉型別中。

最常用的列舉型別 (Enumeration) 是 FindBySubjectName,它會針對指定之存放區內憑證的主體名稱進行不區分大小寫的搜尋。 這可以是不精確的搜尋。 如果找不到憑證,或找到多個符合準則的憑證,將會擲回 InvalidOperationException

適用於