WebRequest.PreAuthenticate 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
当在子类中被重写时,指示是否对请求进行预身份验证。
public:
virtual property bool PreAuthenticate { bool get(); void set(bool value); };
public virtual bool PreAuthenticate { get; set; }
member this.PreAuthenticate : bool with get, set
Public Overridable Property PreAuthenticate As Boolean
属性值
若要进行预身份验证,则为 true
;否则为 false
。
例外
当未在子类中重写该属性时,试图获取或设置该属性。
示例
以下示例将 PreAuthenticate 属性设置为 true
,以便 NetworkCredential 将存储在 属性中的 Credentials 随资源请求一起发送到 。
// Create a new webrequest to the mentioned URL.
WebRequest^ myWebRequest = WebRequest::Create( url );
// Set 'Preauthenticate' property to true. Credentials will be sent with the request.
myWebRequest->PreAuthenticate = true;
Console::WriteLine( "\nPlease enter your credentials for the requested Url" );
Console::WriteLine( "UserName" );
String^ UserName = Console::ReadLine();
Console::WriteLine( "Password" );
String^ Password = Console::ReadLine();
// Create a New 'NetworkCredential' object.
NetworkCredential^ networkCredential = gcnew NetworkCredential( UserName,Password );
// Associate the 'NetworkCredential' object with the 'WebRequest' object.
myWebRequest->Credentials = networkCredential;
// Assign the response object of 'WebRequest' to a 'WebResponse' variable.
WebResponse^ myWebResponse = myWebRequest->GetResponse();
// Create a new webrequest to the mentioned URL.
WebRequest myWebRequest=WebRequest.Create(url);
// Set 'Preauthenticate' property to true. Credentials will be sent with the request.
myWebRequest.PreAuthenticate=true;
Console.WriteLine("\nPlease enter your credentials for the requested Url");
Console.WriteLine("UserName");
string UserName=Console.ReadLine();
Console.WriteLine("Password");
string Password=Console.ReadLine();
// Create a New 'NetworkCredential' object.
NetworkCredential networkCredential=new NetworkCredential(UserName,Password);
// Associate the 'NetworkCredential' object with the 'WebRequest' object.
myWebRequest.Credentials=networkCredential;
// Assign the response object of 'WebRequest' to a 'WebResponse' variable.
WebResponse myWebResponse=myWebRequest.GetResponse();
' Create a new webrequest to the mentioned URL.
Dim myWebRequest As WebRequest = WebRequest.Create(url)
' Set 'Preauthenticate' property to true.
myWebRequest.PreAuthenticate = True
Console.WriteLine(ControlChars.Cr + "Please enter your credentials for the requested Url")
Console.WriteLine("UserName")
Dim UserName As String = Console.ReadLine()
Console.WriteLine("Password")
Dim Password As String = Console.ReadLine()
' Create a New 'NetworkCredential' object.
Dim networkCredential As New NetworkCredential(UserName, Password)
' Associate the 'NetworkCredential' object with the 'WebRequest' object.
myWebRequest.Credentials = networkCredential
' Assign the response object of 'WebRequest' to a 'WebResponse' variable.
Dim myWebResponse As WebResponse = myWebRequest.GetResponse()
注解
除第一个请求外, PreAuthenticate 属性指示是否在不等待服务器质询的情况下发送后续请求的身份验证信息。 当 为 false
时PreAuthenticate,会WebRequest等待身份验证质询,然后再发送身份验证信息。
注意
类 WebRequest 是类 abstract
。 实例在运行时的实际行为 WebRequest 由 方法返回 WebRequest.Create 的后代类确定。 有关默认值和异常的详细信息,请参阅后代类(如 HttpWebRequest 和 FileWebRequest)的文档。
适用于
另请参阅
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈