HttpWebRequest.AllowAutoRedirect Properti
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mendapatkan atau menetapkan nilai yang menunjukkan apakah permintaan harus mengikuti respons pengalihan.
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
Nilai Properti
true jika permintaan harus secara otomatis mengikuti respons pengalihan dari sumber daya Internet; jika tidak, false. Nilai defaultnya adalah true.
Contoh
Contoh kode berikut menggunakan AllowAutoRedirect properti untuk memungkinkan permintaan mengikuti respons pengalihan.
// 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)
Keterangan
Hati
WebRequest, , HttpWebRequestServicePoint, dan WebClient usang, dan Anda tidak boleh menggunakannya untuk pengembangan baru. Gunakan HttpClient sebagai gantinya.
Atur AllowAutoRedirect ke true jika Anda ingin permintaan secara otomatis mengikuti header pengalihan HTTP ke lokasi baru sumber daya. Jumlah maksimum pengalihan yang harus diikuti diatur oleh MaximumAutomaticRedirections properti .
Jika AllowAutoRedirect diatur ke false, semua respons dengan kode status HTTP dari 300 hingga 399 dikembalikan ke aplikasi.
Header Otorisasi dibersihkan pada pengalihan otomatis dan HttpWebRequest secara otomatis mencoba mengautentikasi ulang ke lokasi yang dialihkan. Dalam praktiknya, ini berarti bahwa aplikasi tidak dapat menempatkan informasi autentikasi kustom ke header Otorisasi jika memungkinkan untuk mengalami pengalihan. Sebagai gantinya, aplikasi harus menerapkan dan mendaftarkan modul autentikasi kustom. Kelas System.Net.AuthenticationManager terkait dan digunakan untuk mengimplementasikan modul autentikasi kustom. Metode ini AuthenticationManager.Register mendaftarkan modul autentikasi kustom.