The Mask The Mask - 1 year ago 71
C# Question

How do you prevent the WebClient class from automatically following the location in headers?

Is it possible on the WebClient class?

E.g. something like:

MyWebClient.AllowAutoRedirect = false; (of HttpWebRequest)

Answer Source

You could write a custom web client and enable this functionality:

public class WebClientEx : WebClient
    protected override WebRequest GetWebRequest(Uri address)
        var request = (HttpWebRequest)base.GetWebRequest(address);
        request.AllowAutoRedirect = false;
        return request;

and then:

using (var client = new WebClientEx())
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download