views:

77

answers:

1

Hi Guys,

I'm trying to figure out how many times my web request was redirected before I finally landed at the end content.

I'm creating my web request as follows:

var httpRequest = (HttpWebRequest) WebRequest.Create("some arb path");
httpRequest.AllowAutoRedirect = followRedirects; 

I've had a look at the following URL http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.maximumautomaticredirections.aspx

However, I do not want to impose the limit. I actually want it to follow all redirects (not really wanting a reference to all the URL's), but just for example saying "You have been redirected X times".

I hope there's a quick way to do it as currently I'm assuming I would have to capture all 3xx codes and create a new request for each (hopefully not!).

A: 

There is no way to achieve what you want. You will have to capture each 3xx request and issue a new one with the location header of the redirect.

However, if you want to use native C/C++ code and write directly to WININET (which is the library used by IE) it will provide you (via a callback mechanism) notification for each redirect that happened.

feroze
Giving you a point as you're the only guy that answered (even though I thought of the same solution)
Madabitjer