.Net/C#中Autoproxy配置脚本解析

发布于 2024-07-04 21:00:22 字数 604 浏览 11 评论 0原文

为了让我的应用程序(.Net 1.1)使用系统配置的代理服务器(通过 proxy.pac 脚本),我使用对 WinHTTP 函数 WinHttpGetProxyForUrl 的互操作调用,传递从注册表获得的 proxy.pac url。

不幸的是,我遇到了一个部署场景,这不起作用,因为 proxy.pac 文件本地部署在用户的硬盘驱动器上,并且 url 是“file://C://xxxx”,

正如 WinHttpGetProxyForUrl 中明确指出的文档中,它仅适用于 http 和 https 方案,因此它失败了 file://

我正在考虑解决该问题的 2 个“丑陋”解决方案(pac 文件是 javascript):

  1. 创建一个单独的 JScript.NET 项目,使用具有单个静态方法 Eval(string) 的单个类,并使用它在运行时评估从 pac 文件读取的函数

  2. 在运行时构建 JScript.NET 程序集并加载它。

由于这些解决方案真的很难看:),有人知道更好的方法吗? 是否有可以通过互操作使用的 Windows 功能?

如果没有,你们对上述两种解决方案有何看法 - 您更喜欢哪一种?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

枯叶蝶 2024-07-11 21:00:26

我无法直接回答你的问题,但是从 mozilla 的实现来看,对于支持文件 URL 存在着明确的争论。 这是一场网络控制与本地用户便利性的争论。

I can't answer you question directly, but working from the mozilla implementation there was a definite debate about supporting file URLs. It was a network control vs. local user convenience debate.

独守阴晴ぅ圆缺 2024-07-11 21:00:25

不幸的是,无法回答你的问题(尽管几年前我玩过 jscript.net,这样构建和运行只需要几行)

我遇到了类似的 proxy.pac 问题,并进行了个人解决方案 - -office-proxy 文件不久前 - 最后我选择了最简单的选项并将其放入自己的 IIS 站点中,它坚如磐石,可以完美地与我电脑上的所有内容一起工作。

有时最好屈服并使用所提供的东西:)

Can't answer your problem unfortunately (though a few years ago I played with jscript.net and it would only be a few lines to build and run that way)

I hit a similar proxy.pac hiccup with a personal work-around-the-office-proxy file a while back - in the end I went with the easiest option and dropped it into its own IIS site, and its been rock solid and works flawlessly with everything on my pc.

Sometimes its best to give in and work with what is provided :)

她比我温柔 2024-07-11 21:00:22

只是一个想法:为什么不创建一个可以通过本地主机套接字提供本地 PAC 文件的微型 Web 服务器。 您应该对内容使用随机 URI,以便很难以意外的方式浏览该内容。

然后,您可以将 http://localhost:1234/gfdjklskjgfsdjgklsdfklgfsjkl 之类的 URL 传递给 WinHttpGetProxyForUrl 函数并允许它从您的微型服务器中提取 PAC 文件。

(黑客……黑客……黑客……)

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...)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文