Search code examples
c#jscript.netautoproxy

Autoproxy configuration script parsing in .Net/C#


In order for my application (.Net 1.1) to use the system configured proxy server (trough a proxy.pac script) I was using an interop calls to WinHTTP function WinHttpGetProxyForUrl, passing the proxy.pac url I got from the registry.

Unfortunately, I hit a deployment scenario, where this does not work, as the proxy.pac file is deployed locally on the user's hard drive, and the url is "file://C://xxxx"

As clearly stated in the WinHttpGetProxyForUrl docs, it works only with http and https schemes, so it fails with file://

I'm considering 2 "ugly" solutions to the problem (the pac file is javascript):

  1. Creating a separate JScript.NET project, with a single class with single static method Eval(string), and use it to eval in runtime the function read from the pac file

  2. Building at runtime a JScript.NET assembly and load it.

As these solutions are really ugly :), does anybody know a better approach? Is there a Windows function which I can use trough interop?

If not, what are you guys thinking about the above 2 solutions - which one would you prefer?


Solution

  • Just a thought: Why not create a micro web server that can serve the local PAC file over a localhost socket. You should use a random URI for the content so that it is difficult to browse this in unexpected ways.

    You could then pass a URL like http://localhost:1234/gfdjklskjgfsdjgklsdfklgfsjkl to the WinHttpGetProxyForUrl function and allow it to pull the PAC file from your micro server.

    (hack... hack... hack...)