WindowsServiceCredential.AllowAnonymousLogons 属性

定义

获取或设置一个值,该值指示是否允许匿名用户访问(仅适用于消息级安全性)。

public:
 property bool AllowAnonymousLogons { bool get(); void set(bool value); };
public bool AllowAnonymousLogons { get; set; }
member this.AllowAnonymousLogons : bool with get, set
Public Property AllowAnonymousLogons As Boolean

属性值

Boolean

如果允许匿名用户进行访问,则为 true;否则为 false。 默认值为 false

示例

下面的代码演示如何获取此属性。

// Create a service host.
Uri httpUri = new Uri("http://localhost/Calculator");
ServiceHost sh = new ServiceHost(typeof(Calculator), httpUri);

// Create a binding that uses a WindowsServiceCredential.
WSHttpBinding b = new WSHttpBinding(SecurityMode.Message);
b.Security.Message.ClientCredentialType = MessageCredentialType.Windows;

// Add an endpoint.
sh.AddServiceEndpoint(typeof(ICalculator), b, "WindowsCalculator");

// Get a reference to the WindowsServiceCredential object.
WindowsServiceCredential winCredential =
    sh.Credentials.WindowsAuthentication;
// Print out values.
Console.WriteLine("IncludeWindowsGroup: {0}",
    winCredential.IncludeWindowsGroups);
Console.WriteLine("UserNamePasswordValidationMode: {0}",
    winCredential.AllowAnonymousLogons);

Console.ReadLine();
' Create a service host.
Dim httpUri As New Uri("http://localhost/Calculator")
Dim sh As New ServiceHost(GetType(Calculator), httpUri)

' Create a binding that uses a WindowsServiceCredential.
Dim b As New WSHttpBinding(SecurityMode.Message)
b.Security.Message.ClientCredentialType = MessageCredentialType.Windows

' Add an endpoint.
sh.AddServiceEndpoint(GetType(ICalculator), b, "WindowsCalculator")

' Get a reference to the WindowsServiceCredential object.
Dim winCredential As WindowsServiceCredential = sh.Credentials.WindowsAuthentication
' Print out values.
Console.WriteLine("IncludeWindowsGroup: {0}", winCredential.IncludeWindowsGroups)
Console.WriteLine("UserNamePasswordValidationMode: {0}", winCredential.AllowAnonymousLogons)

Console.ReadLine()

注解

在对绑定使用 Windows 客户端凭据时,默认情况下,系统不允许匿名访问。 这意味着只有经过身份验证的域或工作组用户可以访问系统。 但在某些情况下,未经身份验证的匿名用户也可以访问服务。 在这种情况下,可以将此属性设置为 true,以允许匿名客户端调用服务。 如果服务允许匿名身份验证,则安全性要求会大幅度降低,因此,应小心使用此设置。

请注意,此属性不适用于传输安全情况,而只适用于基础绑定使用消息安全来保护消息的情况。 在使用 Windows 传输安全的情况下,此属性不适用。

适用于