I have the following problem there are web site that does redirection to another websites and then to another website sites.....(like a 20 redirection), I read that the object HttpWebRequest has the property MaximumAutomaticRedirections, I set this property to 10 times and check with a web site that do redirection in the Javascrip like(Client Side):

<script>
window.location = "http://www.anotherwebsite.com";
</script>

I see that I redirect all the time, I was wandering if can can set a number of re directions I want to allow, currently my code is not working.

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(myURLl);
request.MaximumAutomaticRedirections = redirectionTimes;
response = (HttpWebResponse)request.GetResponse();

I see that doesn't matter how many redirection the website does, I allow all of them? Is possible to allow only a specif numer if the re directions are done in the Client Side
Thanks

That doesn't make any sense. All of the redirections are done client side. The server sends an HTTP 301/302, uses a meta refresh, or various other methods to redirect.

Unfortunately for you the HTTPWebRequest doesn't respect all redirections that a browser might as it is not script-aware, it will fetch the data and listen for HTTP Codes (like 301/302 redirects) but not java redirects. You need to test the content you are about to server before you embed is my only suggestion.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.