Delivering solid user friendly software solutions since the dawn of time.

System.Net.WebException Too many automatic redirections were attempted

Categories: .Net

Assuming you do not need more then 50 redirects, your webpage probably redirects because of a missing cookie. Which can not be set because you didn't add a cookie container...

var request = (HttpWebRequest)WebRequest.Create(url);
request.Method = WebRequestMethods.Http.Get;
request.CookieContainer = new CookieContainer();
using (var response = (HttpWebResponse)request.GetResponse())
using (var stream = new StreamReader(response.GetResponseStream()))
string html = stream.ReadToEnd();

In case you do need more redirects or more likely less... you can set this property:

request.MaximumAutomaticRedirections = 5;