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)

注釈

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

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

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

適用対象