閱讀英文 編輯

共用方式為


WindowsClientCredential.ClientCredential Property

Definition

Gets or sets the Windows client credential.

C#
public System.Net.NetworkCredential ClientCredential { get; set; }

Property Value

The NetworkCredential for the client.

Examples

The following code examples show how to authenticate the client as a different principal.

This is how to change the properties of the instance of the NetworkCredential class that is returned by this property.

C#
private void Snippet2()
{
    using (CalculatorClient client = new CalculatorClient())
    {
        client.ClientCredentials.Windows.ClientCredential.UserName = "test";
        client.ClientCredentials.Windows.ClientCredential.Password = "password";
    }
}

This is how to create a new instance of the NetworkCredential class and assign it to this property.

C#
private void Snippet3()
{
    using (CalculatorClient client = new CalculatorClient())
    {
        client.ClientCredentials.Windows.ClientCredential = new NetworkCredential("test user", "password");
    }
}

Remarks

By default, the current thread's credentials are used by WCF for doing Windows SSPI Negotiate authentication.

To authenticate the client as another principal, change the properties of the instance of the NetworkCredential class that is returned by this property. Alternatively, create a new instance of the NetworkCredential class and assign it to this property.

Applies to

產品 版本
.NET Core 1.0, Core 1.1, 8 (package-provided), 9 (package-provided)
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
UWP 10.0