设置默认的代理编程,而不是使用的app.config [英] set default proxy programmatically instead of using app.config

查看:367
本文介绍了设置默认的代理编程,而不是使用的app.config的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为一个代理之后,我的.Net 4.0 C#应用程序只能在有一个app.config包含以下内容:

Being behind a proxy, my .Net 4.0 C# application only works when there is an app.config with the following content:

<system.net>
    <defaultProxy enabled="true" useDefaultCredentials="true">
        <proxy />
        <bypasslist />
        <module />
    </defaultProxy>
</system.net>

现在,因为我不希望有一个app.config而且由于嵌入的app.config不推荐,什么是C#code具有同等效力XML块在App.config在哪里我把它?

Now since I don't want to have an app.config and since embedding app.config is not recommended, what is the C# code that has the same effect as that xml chunk in the app.config and where do I place it?

推荐答案

您可以使用<一个href="http://msdn.microsoft.com/en-us/library/system.net.webrequest.defaultwebproxy.aspx">WebRequest.DefaultWebProxy或<一href="http://msdn.microsoft.com/en-us/library/system.net.globalproxyselection.aspx">GlobalProxySelection.Select

System.Net.GlobalProxySelection.Select = new WebProxy(ip,port);

System.Net.WebRequest.DefaultWebProxy = new WebProxy(ip,port);

这篇关于设置默认的代理编程,而不是使用的app.config的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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