禁用整个应用程序的代理? [英] Disable proxy for entire application?

查看:68
本文介绍了禁用整个应用程序的代理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自从升级到 Visual Studio 2010 后,我遇到了一个问题,即任何类型(WebRequest、WebClient 等)的第一个 Web 请求在完成前挂起大约 20 秒.后续呼叫工作迅速.我已将问题缩小到代理问题.

Ever since upgrading to Visual Studio 2010, I'm running into an issue where the first web request of any type (WebRequest, WebClient, etc.) hangs for about 20 seconds before completing. Subsequent calls work quickly. I've narrowed down the problem to a proxy issue.

如果我手动禁用代理设置,我不会遇到这种延迟:

If I manually disable proxy settings, I don't experience this delay:

Dim wrq As WebRequest = WebRequest.Create(Url)
wrq.Proxy = Nothing

奇怪的是,这台机器在Internet选项中没有启用代理设置.我想知道的是,是否有一种方法可以一次性禁用整个项目的代理设置,而无需像上述那样为每个 Web 对象明确禁用.

What's strange is that there are no proxy settings enabled on this machine in Internet Options. What I'm wondering is if there is a way to disable proxy settings for my entire project in one shot without explicitly disabling as above for every web object.

我希望能够做到这一点的主要原因是我正在尝试使用 API (http://code.google.com/p/google-api-for-dotnet/),它使用网络请求,但不提供任何手动禁用代理设置的方法.

The main reason I want to be able to do this is that I'm trying to use an API (http://code.google.com/p/google-api-for-dotnet/) which uses web requests, but does not provide any way to manually disable proxy settings.

我发现一些信息表明我需要向 app.config 文件添加一些代理信息,但是如果我对该文件进行编辑,我会在构建我的程序时出错.

I have found some information suggesting that I need to add some proxy information to the app.config file, but I get errors building my program if I make an edits to that file.

谁能指出我正确的方向?

Can anyone point me in the right direction?

推荐答案

Brent - 这是正确的解决方案:添加一个 defaultProxy 元素 到您的应用程序的配置文件.

Brent - that's the correct solution : adding a defaultProxy element to your application's configuration file.

所以对于网站来说,就是 web.config.对于 .exe 应用程序,它是 .config.

So for a website, it's the web.config. For an .exe application, it's .config.

而且这些设置也是正确的:-

And those settings are also correct :-

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.net>
        <defaultProxy enabled="false" useDefaultCredentials="false">
            <proxy/>
            <bypasslist/>
            <module/>
        </defaultProxy>
    </system.net>
</configuration>

这篇关于禁用整个应用程序的代理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆