IntranetZoneCredentialPolicy 类

定义

定义凭据策略,该凭据策略将用于使用 WebRequest 及其派生类发出的资源请求。Defines a credential policy to be used for resource requests that are made using WebRequest and its derived classes.

public ref class IntranetZoneCredentialPolicy : System::Net::ICredentialPolicy
public class IntranetZoneCredentialPolicy : System.Net.ICredentialPolicy
type IntranetZoneCredentialPolicy = class
    interface ICredentialPolicy
Public Class IntranetZoneCredentialPolicy
Implements ICredentialPolicy
继承
IntranetZoneCredentialPolicy
实现

示例

下面的代码示例演示如何创建的IntranetZoneCredentialPolicy实例, 并使用它来设置应用程序域的凭据策略。The following code example demonstrates creating an instance of IntranetZoneCredentialPolicy and using it to set the credential policy for the application domain.

static void UseIntranetCredentialPolicy()
{
   IntranetZoneCredentialPolicy^ policy = gcnew IntranetZoneCredentialPolicy;
   AuthenticationManager::CredentialPolicy = policy;
}
 public static void UseIntranetCredentialPolicy()
{
    IntranetZoneCredentialPolicy  policy = new IntranetZoneCredentialPolicy();
    AuthenticationManager.CredentialPolicy = policy;
}

注解

此策略只允许在请求的资源与发出请求的客户端位于同一个域中时发送凭据。This policy allows credentials to be sent only if the requested resource is in the same domain as the client that is making the request. 对于许多应用程序, 这是最佳策略, 因为它可以防止向不在 intranet 上的资源请求发送网络凭据。For many applications this is the optimal policy because it prevents network credentials from being sent with requests for resources that are not on the intranet.

备注

ICredentialPolicy仅当WebRequest与请求关联的WebProxy或具有不null具有的凭据时, 才会调用策略。ICredentialPolicy policies are invoked only if the WebRequest or the WebProxy that is associated with the request has credentials that are not null. 设置此策略不会影响未指定凭据的请求。Setting this policy has no effect on requests that do not specify credentials.

AuthenticationManager.CredentialPolicy使用属性IntranetZoneCredentialPolicy设置策略。Use the AuthenticationManager.CredentialPolicy property to set the IntranetZoneCredentialPolicy policy. 处理请求身份验证的会在执行身份验证ShouldSendCredential之前调用方法。 IAuthenticationModuleThe IAuthenticationModule that handles authentication for the request will invoke the ShouldSendCredential method before performing the authentication. 如果请求的资源与客户端位于不同的域中, 则ShouldSendCredential该方法false将返回, 并且不执行身份验证。If the requested resource is in a different domain than the client, the ShouldSendCredential method returns false, and authentication is not performed.

此策略会影响当前应用WebRequest程序域中具有非 null 凭据的的所有实例。This policy affects all instances of WebRequest with non-null credentials in the current application domain. 无法在单个请求中重写此策略。The policy cannot be overridden on individual requests.

构造函数

IntranetZoneCredentialPolicy()

初始化 IntranetZoneCredentialPolicy 类的新实例。Initializes a new instance of the IntranetZoneCredentialPolicy class.

方法

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ShouldSendCredential(Uri, WebRequest, NetworkCredential, IAuthenticationModule)

返回一个 Boolean,该值指示客户端的凭据是否随使用 WebRequest 发出的资源请求一起发送。Returns a Boolean that indicates whether the client's credentials are sent with a request for a resource that was made using WebRequest.

ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

适用于