title: Using Proxy Automatic Configuration from IE Settings in .Net
body: <p>I'm having trouble getting Proxy Automatic Configuration (PAC) in IE options to work as expected using .Net WebRequest.</p>
  
  <p>According to this article:<br>
  <a href="http://web.archive.org/web/20120329222856/http://msdn.microsoft.com/en-gb/magazine/cc300743.aspx" rel="nofollow noreferrer">Proxy Detection
  Take the Burden Off Users with Automatic Configuration in .NET</a> </p>
  
  <p>The system proxy should be set by default with to each WebRequest.</p>
  
  <p>That's how the proxy.js pac file looks like:</p>
  
  <pre><code>function FindProxyForURL(url, host)
  {
    return "PROXY ProxyServerName:3118; DIRECT;";
  }
  </code></pre>
  
  <p>I also took a look at this post: <a href="https://stackoverflow.com/questions/299940/how-should-i-set-the-default-proxy-to-use-default-credentials">How should I set the default proxy to use default credentials?</a></p>
  
  <p>Which suggests to add this in the app.config:</p>
  
  <pre><code>&lt;system.net&gt;
    &lt;defaultProxy useDefaultCredentials="true" /&gt;
  &lt;/system.net&gt;
  </code></pre>
  
  <p>Adding this did not help.</p>
  
  <p>I created a small console application just to test this out.. here it is:</p>
  
  <pre><code>static void Main(string[] args)
  {
      HttpWebRequest request = null;
      try
      {               
          String resolvedAddress = WebRequest.DefaultWebProxy.GetProxy(new Uri("http://www.google.com")).ToString();
          Console.WriteLine("Proxy for address is: " + resolvedAddress);
  
          Uri m_URLToTest = new Uri("http://www.google.com");
          request = WebRequest.Create(m_URLToTest) as HttpWebRequest;
          request.Method = "GET";
          request.KeepAlive = false;
          request.Timeout = 5000;
          request.Proxy = WebRequest.DefaultWebProxy;
          WebResponse response = request.GetResponse();
          StreamReader reader = new StreamReader(response.GetResponseStream());
          string message = reader.ReadToEnd();
      }
      catch (Exception ex)
      {
          Console.Write("Exception");
      }
  
  }
  </code></pre>
  
  <p>The output:
  Proxy for address is <a href="http://www.google.com" rel="nofollow noreferrer">http://www.google.com</a></p>
  
  <p>instead of Proxy for address is ProxyServerName:3118</p>
  
  <p>It happens only when using auto configuration script...</p>
  
  <p>Did I miss anything? Please help!</p>