locked
Too many automatic redirections were attempted? RRS feed

  • Question

  • User2050878018 posted

    I'm having  this error while trying to read the product detail page(incluing images, some ascx ) of a Web page,so I can send them in an email to recommend to my friends..kind of ------"Email to friend"
    "Too many automatic redirections were attempted."

    This is the code I am using

    public static string GetHtml(string urlAddr)

    {

          if (urlAddr == null || string.IsNullOrEmpty(urlAddr) )

          {

             throw new ArgumentNullException("urlAddr");

          }

          else

          {

                string result;

                WebRequest request = HttpWebRequest.Create(new Uri(urlAddr));

                WebResponse response = request.GetResponse();

                using (StreamReader sr = new StreamReader(response.GetResponseStream()))

                {

                   result = sr.ReadToEnd();

                   //Close and clean up the StreamReader

                   sr.Close();

             }

             return result;

          }

    }

    =============================================================

    mail.Body = em.BodyText + HtmlScraper.GetHtml(ed.UrlAddress);

    ==============================================================

    Thank you for any help in advance...

     

    Thursday, August 3, 2006 11:16 AM

All replies

  • User1439829176 posted
    The url you are trying to reach have to many response.redirect. Maybe there's an infinite number of redirect in that page. Try fetching the data at the last location.
    Thursday, August 3, 2006 2:00 PM
  • User-1639117814 posted

    By default HttpWebRequest allows 50 redirections before it bails out which is a pretty high number. There seems to be some kind of infinite loop going in the redirections from that site. If you can post the original url then I can try to figue out whats going on. We use our HTMLParser.Net library to detect these kind of issues.

     

    http://www.netomatix.com

     

    Thursday, August 3, 2006 4:26 PM
  • User2050878018 posted

    Thx.. I've tried to test another way, and in this case I do not have error message but the image and css are borken. Is there any way to send Product detail.aspx(incluing master page and some ascx pages) to friend..."Email to Friend"?

            public static string GetHtml(string urlAddr)
            {
                if (urlAddr == null || string.IsNullOrEmpty(urlAddr))
                {
                    throw new ArgumentNullException("urlAddr");
                }
                else
                {
                    string result;

                    //1.Create the request object
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(urlAddr);
                    //request.AllowAutoRedirect = true;
                    //request.MaximumAutomaticRedirections = 200;
                    request.Proxy = null;
                    request.UseDefaultCredentials = true;

                    //2.Add the container with the active
                    CookieContainer cc = new CookieContainer();
                   

                    //3.Must assing a cookie container for the request to pull the cookies
                    request.CookieContainer = cc;

                    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                    using (StreamReader sr = new StreamReader(response.GetResponseStream()))
                    {
                        result = sr.ReadToEnd();
                        //Close and clean up the StreamReader
                        sr.Close();
                    }
                    return result;
                }
            }

     

    Thursday, August 3, 2006 4:52 PM
  • User-1639117814 posted

    Images and CSS probably would be broken because they are pinting to realtive paths. Your GetHtml function only returns the HTML part response from the URL.

    Thursday, August 3, 2006 5:24 PM
  • User2050878018 posted

    Thank you for your help. I'm having two questions.

    One is what is exactly 50 redirections ? does it mean to link to go somewhere

    The other is  there is any sample to send an email with a web page to tell a friend

    Thanks again.

     

    Friday, August 4, 2006 9:03 AM
  • User-1639117814 posted

    Redirection means that when you sent the request to URL for response, the web server responded with an HTTP Code 307 telling that URL has been moved to some other location and then the next one did the same thing. And then HttpWebRequest tries to send the request to new URL. If there are way too many redirections in one request then you will get exception.

    Don't know of any sample that would send page in email. You can always send the link to your friend [:)]

    Friday, August 4, 2006 9:23 AM
  • User28222024 posted

    Did u get any solution, I am also having a same problem, Please have a look into the problem, if you got any solution let me know.

     http://forums.asp.net/p/1160402/1917054.aspx#1917054

     Regards

    Hasan

    Thursday, September 20, 2007 4:57 AM
  • User1050404249 posted

    hi,

    i had this error but got a simple fix
    you don't need all that code, all you need is to do is in the beginning of your application download the cookie like this (sorry but i work with VB :) but is pretty simple to convert)

    [your application namespace].Application.GetCookie(New Uri("https://[site]"))


    Greetings from Portugal
    Gandum

    Thursday, July 5, 2018 9:41 AM