HttpWebRequest.AllowAutoRedirect プロパティ

定義

要求がリダイレクト応答に従う必要があるかどうかを示す値を取得または設定します。

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

プロパティ値

要求がインターネット リソースからのリダイレクト応答に自動的に従う必要があるかどうかを true します。それ以外の場合は、falseします。 既定値は trueです。

次のコード例では、AllowAutoRedirect プロパティを使用して、要求がリダイレクト応答に従うことを許可します。

// Create a new HttpWebRequest Object to the mentioned URL.
HttpWebRequest^ myHttpWebRequest = (HttpWebRequest^)( WebRequest::Create( "http://www.contoso.com" ) );
myHttpWebRequest->MaximumAutomaticRedirections = 1;
myHttpWebRequest->AllowAutoRedirect = true;
HttpWebResponse^ myHttpWebResponse = (HttpWebResponse^)( myHttpWebRequest->GetResponse() );
// Create a new HttpWebRequest Object to the mentioned URL.
HttpWebRequest myHttpWebRequest=(HttpWebRequest)WebRequest.Create("http://www.contoso.com");	
myHttpWebRequest.MaximumAutomaticRedirections=1;
myHttpWebRequest.AllowAutoRedirect=true;
HttpWebResponse myHttpWebResponse=(HttpWebResponse)myHttpWebRequest.GetResponse();

     'This method creates a new HttpWebRequest Object to the mentioned URL.
         Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create("http://www.contoso.com"), HttpWebRequest)
         myHttpWebRequest.MaximumAutomaticRedirections = 1
         myHttpWebRequest.AllowAutoRedirect = True
         Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)

注釈

注意

WebRequestHttpWebRequestServicePointWebClient は廃止されており、新しい開発には使用しないでください。 代わりに HttpClient を使用してください。

要求がリソースの新しい場所に HTTP リダイレクト ヘッダーに自動的に従う場合は、AllowAutoRedirecttrue に設定します。 後続するリダイレクトの最大数は、MaximumAutomaticRedirections プロパティによって設定されます。

AllowAutoRedirectfalseに設定されている場合、HTTP 状態コードが 300 から 399 のすべての応答がアプリケーションに返されます。

自動リダイレクトでは Authorization ヘッダーがクリアされ、HttpWebRequest は自動的にリダイレクトされた場所への再認証を試みます。 実際には、リダイレクトが発生する可能性がある場合、アプリケーションはカスタム認証情報を Authorization ヘッダーに入れることはできません。 代わりに、アプリケーションでカスタム認証モジュールを実装して登録する必要があります。 System.Net.AuthenticationManager および関連するクラスは、カスタム認証モジュールを実装するために使用されます。 AuthenticationManager.Register メソッドは、カスタム認証モジュールを登録します。

適用対象