次の方法で共有


HttpWebRequest.AllowAutoRedirect プロパティ

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

Public Property AllowAutoRedirect As Boolean
[C#]
public bool AllowAutoRedirect {get; set;}
[C++]
public: __property bool get_AllowAutoRedirect();public: __property void set_AllowAutoRedirect(bool);
[JScript]
public function get AllowAutoRedirect() : Boolean;public function set AllowAutoRedirect(Boolean);

プロパティ値

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

解説

要求を HTTP リダイレクト ヘッダーに自動的に従わせ、リソースの新しい場所に移動する場合は、 AllowAutoRedirecttrue に設定します。実行するリダイレクトの最大数は、 MaximumAutomaticRedirections プロパティで設定します。

AllowAutoRedirect が false に設定されている場合、HTTP ステータス コードが 300 ~ 399 の範囲の応答はすべて、アプリケーションに返されます。

使用例

[Visual Basic, C#, C++] AllowAutoRedirect プロパティを使用して、要求がリダイレクト応答に従うようにする例を次に示します。

 

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

[C#] 
// Create a new HttpWebRequest Object to the mentioned URL.
HttpWebRequest myHttpWebRequest=(HttpWebRequest)WebRequest.Create("https://www.contoso.com");    
myHttpWebRequest.MaximumAutomaticRedirections=1;
myHttpWebRequest.AllowAutoRedirect=true;
HttpWebResponse myHttpWebResponse=(HttpWebResponse)myHttpWebRequest.GetResponse();    

[C++] 
// Create a new HttpWebRequest Object to the mentioned URL.
HttpWebRequest* myHttpWebRequest =
   dynamic_cast<HttpWebRequest*>(WebRequest::Create(S"https://www.contoso.com"));
myHttpWebRequest->MaximumAutomaticRedirections=1;
myHttpWebRequest->AllowAutoRedirect=true;
HttpWebResponse* myHttpWebResponse =
   dynamic_cast<HttpWebResponse*>(myHttpWebRequest->GetResponse());

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard

参照

HttpWebRequest クラス | HttpWebRequest メンバ | System.Net 名前空間