Wednesday, September 13, 2017

Configuring Windows to use a PAC File or Proxy Server

This post demonstrates configuring Windows to make use of a PAC file and/or Proxy server. These settings apply to a given user rather then applying to an application that programmatically species a PAC file or proxy server. All .NET applications that adhere to standard programming principles will make sure of the PAC file and/or proxy server information specified for a given user.  As an example, the following rather mundane code will route the request to google.com through a proxy server if one has been configured for a given user on Windows:

class Program
{
  static void Main(string[] args)
  {
    using (WebClient webClient = new WebClient())
    {
      string str = webClient.DownloadString(
                     "http://www.google.com");

      Console.WriteLine(str);
    }
  }                           
}

Notice in the above sample there is no code whose purpose is to set up or configure a PAC file or proxy server. It all just works under the covers. The PAC file and/or proxy server can be set using “Auto proxy configuration settings for Internet Explorer.”

As an example of how a PAC File and Proxy can be set using “Auto proxy configuration settings for Internet Explorer” is as follows:

  1. Launch Internet Explorer
  2. Click on the gear icon in the upper right corner and select Internet options:


  1. Click on the Internet options menu item displays the Internet Options dialog. From the Internet Options dialog select the Connection tab (see below):


  1. On the Internet Options dialog, click on the LAN settings button which displays the Local Area Network (LAN) Settings dialog:


  1. The Local Area Network (LAN) Settings dialog is organized as follows:
    1. The group box at the top is entitled “Automatic configuration” and the purpose of this section is to assign a PAC File that can be used by the Windows (including .NET applications).
    2. The group box at the bottom is entitled, “Proxy server” and the purpose of this section is to assign a Proxy Server to be used by Windows (including .NET applications).
  2. To assign a PAC File that will be used by Windows applications configuration the Local Area Network (LAN) Settings dialog as follows:

  1. Note that in the screenshot above that
    1. The checkbox “Automatically detect settings” was checked so that applications will pickup the specific PAC File automatically.
    2. The checkbox “Use automatic configuration script” when checked enables a text box in which a PAC File (which is really a URL pointing to a file) can be specified.
  2. To assign a Proxy Server that will be used by Windows applications configuration the Local Area Network (LAN) Settings dialog as follows:

  1. Note that in the screenshot above that
    1. The checkbox “use a proxy server for your LAN” was checked so that applications will pickup the specific Proxy Server automatically.
    2. The text boxes below this check box allow the proxy server host and the port it listens on to be specified
    3. The checkbox “Bypass proxy server for local address” when checked enables a application to make calls against local host. Such calls are necessary, for example, when performing OAuth authentication against Google. A local browser (127.0.0.1) is used to retrieve the authentication code returned by Google.
Notice that there is no way to specify user credentials with regards to the proxy or proxies specified in the PAC file (top portion of the Local Area Network (LAN) Settings dialog). Also notice that there is no way to specify user credentials with regards to the proxy server specified in the lower portion of the Local Area Network (LAN) Settings dialog.  By default applications use the default login credentials to access a proxy server.











No comments :

Post a Comment