diff --git a/src/HtmlAgilityPack.Shared/HtmlWeb.cs b/src/HtmlAgilityPack.Shared/HtmlWeb.cs
index eb29af86..81247119 100644
--- a/src/HtmlAgilityPack.Shared/HtmlWeb.cs
+++ b/src/HtmlAgilityPack.Shared/HtmlWeb.cs
@@ -89,6 +89,7 @@ public partial class HtmlWeb
private string _cachePath;
private bool _fromCache;
+ private int _maxAutoRedirects = 50;
private int _requestDuration;
private Uri _responseUri;
private HttpStatusCode _statusCode = HttpStatusCode.OK;
@@ -802,6 +803,17 @@ internal static HttpClient GetSharedHttpClient(string userAgent)
/// The automatic decompression.
public DecompressionMethods AutomaticDecompression { get; set; }
+ ///
+ /// Maximum number of redirects that will be followed.
+ /// To disable redirects, do not set the value to 0, please set CaptureRedirect to 'true'.
+ ///
+ /// Must be greater than 0, Default is 50.
+ public int MaxAutoRedirects
+ {
+ set { if (value <= 0) { throw new ArgumentOutOfRangeException(); } else { _maxAutoRedirects = value; } }
+ get { return _maxAutoRedirects; }
+ }
+
///
/// Gets or sets the timeout value in milliseconds. Must be greater than zero. A value of -1 sets the timeout to be infinite.
///
@@ -1581,6 +1593,7 @@ private HttpStatusCode Get(Uri uri, string method, string path, HtmlDocument doc
bool oldFile = false;
req = WebRequest.Create(uri) as HttpWebRequest;
+ req.MaximumAutomaticRedirections = MaxAutoRedirects;
req.Timeout = Timeout;
req.Method = method;
req.UserAgent = UserAgent;
@@ -1853,6 +1866,7 @@ private HttpStatusCode Get(Uri uri, string method, string path, HtmlDocument doc
using (var client = new HttpClient(handler))
{
client.Timeout = TimeSpan.FromMilliseconds(Timeout);
+ handler.MaxAutomaticRedirections = MaxAutoRedirects;
if(CaptureRedirect)
{