WebRequest.PreAuthenticate Proprietà

Definizione

Quando ne viene eseguito l'override in una classe discendente, indica se è necessario preautenticare la richiesta.

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

Valore della proprietà

true per preautenticare; in caso contrario, false.

Eccezioni

Viene eseguito un tentativo per ottenere o impostare la proprietà quando quest'ultima non è sottoposta a override in una classe discendente.

Esempio

Nell'esempio seguente la PreAuthenticate proprietà viene impostata su true in modo che l'oggetto NetworkCredential archiviato nella Credentials proprietà venga inviato insieme alla richiesta di risorsa.

// 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()

Commenti

Ad eccezione della prima richiesta, la PreAuthenticate proprietà indica se inviare informazioni di autenticazione con richieste successive senza attendere che il server venga contestato. Quando PreAuthenticate è false, attende WebRequest una richiesta di autenticazione prima di inviare informazioni di autenticazione.

Nota

La WebRequest classe è una abstract classe . Il comportamento effettivo delle istanze in fase di WebRequest esecuzione è determinato dalla classe discendente restituita dal WebRequest.Create metodo . Per altre informazioni sui valori e le eccezioni predefiniti, vedere la documentazione per le classi discendenti, ad esempio HttpWebRequest e FileWebRequest.

Si applica a

Vedi anche