Skip to main content
Home Forums Silverlight Programming Report a Silverlight Bug HttpWebRequest infinite loop handling error 301: Moved Permanently
2 replies. Latest Post by andulvar on November 28, 2008.
(0)
andulvar
Member
143 points
101 Posts
11-22-2008 9:44 AM |
I am using the asynchronous read capability of HttpWebRequest, like this:
private void ReadHandler(object userdata) { object[] args = (object[])userdata; HttpWebRequest w = (HttpWebRequest)args[0]; RequestState req = (RequestState)args[1]; IAsyncResult result = w.BeginGetResponse(new AsyncCallback(RespCallback), req); }
This works fine, unless the requested URL does not exist. If the web server returns "404: Not Found", then the "RespCallback" is called and the call completes.
However, if the web server returns "301: Moved Permanently" then the RespCallback is never called and the Silverlight application modifies the URL and repeats the request forever. The sequence of requests as received by the web server looks like this:
The correct request comes first:
GET /Silverlight/Controls/TripleGauge.xaml?_sldummy=06f631f4-0527-4ec6-875a-013a5c576566 HTTP/1.1Accept: */*UA-CPU: x86Accept-Encoding: gzip, deflateUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)Host: developers.cogentrts.com:8088Connection: Keep-Alive
The first re-request. Notice that the arguments have been stripped and a / added to the URL. This is just plain wrong. The arguments are a necessary part of the URL.
GET /Silverlight/Controls/TripleGauge.xaml/ HTTP/1.1Accept: */*UA-CPU: x86Accept-Encoding: gzip, deflateUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)Host: developers.cogentrts.com:8088Connection: Keep-Alive
Now a second / has been added to the URL and the arguments are still missing.
GET /Silverlight/Controls/TripleGauge.xaml// HTTP/1.1Accept: */*UA-CPU: x86Accept-Encoding: gzip, deflateUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)Host: developers.cogentrts.com:8088Connection: Keep-Alive
All subsequent requests look like the third one. This repeats forever.
Since 301 is a permanent error, why is Silverlight making any repeated calls at all?
Even if you can explain the re-try, why is it stripping the arguments, thereby potentially generating a completely different response page?
Why is it looping forever with the same URL? Isn't the definition of insanity "repeating the same thing over and over, and expecting a different result"?
Jonathan...
All-Star
23562 points
2,304 Posts
11-27-2008 10:19 PM |
Hi Andulvar,
We conducted a 301 error from the target website and added this kind of the test code to see whether your issue can be reproduced.
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(new Uri("http://localhost:61928/Default.aspx")); wr.BeginGetResponse(result => { HttpWebResponse hwr = (HttpWebResponse)wr.EndGetResponse(result); //add a break point here }, wr);
It works as desired and not like your description. For the asynchronous request, please follow this sample.
Best regards,
Jonathan
11-28-2008 5:53 AM |
I followed the code in one of the examples in the Silverlight documentation. The fact that your test did not reproduce the error only tells us that you don't have a representative test. I can tell you with absolute certainty that the request is being retried. I ran the web server in a debugger and watched the requests as they arrived. A single call to BeginGetResponse generates multiple web server hits, and they will repeat indefinitely so long as the web server continues to respond with 301.