我需要包含这样的代码:
IWebProxy proxy = new WebProxy(Proxy, ProxyPort); NetworkCredential nc = new NetworkCredential(); nc.UserName = ProxyLogin; nc.Password = ProxyPassword; proxy.Credentials = nc; WebRequest.DefaultWebProxy = proxy;
在我的WebForm应用程序中.但我项目的很多部分都是从不同的地方开始的:不同的主页,用ajax调用的单页等等!
我可以把它放在一个共同的地方吗?所以每次调用页面都能保证我的WebRequest使用代理....
您可以将它放在Global.asax.cs 中的应用程序级事件处理程序中,例如BeginRequest:
void Application_BeginRequest(Object sender, EventArgs e) { // your code goes here }