Geeks With Blogs
Tim Huffam Dotting the I and crossing the T of I.T.

This error can occur when an application performs a web request to a web app that's trying to interogate the Request.UserAgent - but the requesting app has not set the user agent in the request.

To resolve either set the user agent before sending the request eg:

HttpWebRequest req = (HttpWebRequest) HttpWebRequest.Create(theUrl);
req.UserAgent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";

Alternatively, and preferrably (if you have access to it), fix the server side web application to check Request.UserAgent for null or blank values before performing any operations on it.

HTH

Tim

Posted on Tuesday, July 4, 2006 2:45 AM C# .NET , ASP.NET | Back to top


Comments on this post: Error: System.Net.WebException: Too many automatic redirections attempted.

# re: Error: System.Net.WebException: Too many automatic redirections attempted.
Requesting Gravatar...
Hi, you suggested tips not working.
Left by Devanathan C on Oct 06, 2009 7:21 AM

# re: Error: System.Net.WebException: Too many automatic redirections attempted.
Requesting Gravatar...
I can't tell you the frustration you've saved me from with this post! I'm using the mobile toolkit by 51 degrees, which apparently does exactly this...

so when I was trying to call a page with WebRequest, since I didn't have a user agent set, it kept giving me the redirections error.

Adding your user agent string to the request stopped the error!

THANK YOU!!
Left by Josh on Jul 13, 2010 3:55 PM

# re: Error: System.Net.WebException: Too many automatic redirections attempted.
Requesting Gravatar...
hi friends;
I have to connect to pass a url through an iron gate proxy to dowload a xml file. I tried both webclient and httpweberquest method. both are returning "Too many automatic redirections attempted". Any help wil be appreciated.

--------------------------------------------
Dim dsXMLLIC As New DataSet
Dim arByte() As Byte


Try

Dim sibproxy As New WebProxy("10.1.221.50", 3128)
sibproxy.Credentials = New NetworkCredential("sib5157", "ecec12345")

''----->>>> Web Client Method ---------<<<
Dim siblicClnt As New WebClient
siblicClnt.Proxy = sibproxy
' arByte = siblicClnt.DownloadData(pstrURL)
Dim MemStream As New MemoryStream(siblicClnt.DownloadData(pstrURL))
dsXMLLIC.ReadXml(MemStream)
'' siblicClnt.OpenRead("http://www.google.com")
''----->>>> Web Client Method ---------<<<


''----->>>> Http Web Request Method ---------<<<

Dim httpreq As HttpWebRequest = HttpWebRequest.Create(pstrURL)
''Dim httpreq As HttpWebRequest = WebRequest.Create("http://www.google.com")
Dim cookCont As New CookieContainer()
httpreq.CookieContainer = cookCont

httpreq.Proxy = sibproxy
httpreq.Credentials = New NetworkCredential("sib5157", "ecec12345")
httpreq.AllowAutoRedirect = True
httpreq.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0b; Windows NT 5.0)"
''httpreq.MaximumAutomaticRedirections = 30
''httpreq.Method = "GET"
Dim webres As HttpWebResponse = httpreq.GetResponse()

Dim responseStream As Stream
responseStream = webres.GetResponseStream()
''responseStream.Seek(0, SeekOrigin.Begin)
Dim sr As StreamReader = New StreamReader(responseStream)
' Dim respString As String = sr.ReadToEnd()
Dim xmlred As XmlReader = New XmlTextReader(sr)
dsXMLLIC.ReadXml(xmlred)

doConnectProxy = True

''----->>>> Http Web Request Method ---------<<<

Catch ex As Exception
doConnectProxy = False
End Try

----------------------------------------

Giju V.
Left by Giju V. on Jan 25, 2011 5:14 AM

Your comment:
 (will show your gravatar)


Copyright © Tim Huffam | Powered by: GeeksWithBlogs.net