1

I want to set a proxy in C#.NET, the thing is, how would I make it so that all web requests and web browser controls connect through the proxy? Like a SOCKS proxy?

I need it to apply to any web browser controls or any web requests. It would be best if I could just set it so all outgoing requests from the user's machine is sent through the proxy.

Bob
  • 417
  • 2
  • 7
  • 13

1 Answers1

0

By default, your C# code will use the system proxy set in your IE connection settings.

If you want to be explicit, you can do it via config under System.net:

<defaultProxy useDefaultCredentials="true">
    <proxy usesystemdefault="true" proxyaddress="[proxy address]" bypassonlocal="true" />
</defaultProxy>

Programmatically, you can set the proxy:

http://msdn.microsoft.com/en-us/library/system.net.webproxy.aspx

WebProxy proxyObject = new WebProxy("http://proxyserver:80/",true);
WebRequest req = WebRequest.Create("http://www.contoso.com");
req.Proxy = proxyObject;

EDIT: For web browser control, try this SO post: (disclaimer - haven't tried that)

How to set a proxy for Webbrowser Control without effecting the SYSTEM/IE proxy

Community
  • 1
  • 1
bryanmac
  • 38,941
  • 11
  • 91
  • 99
  • I understand, but will the WebProxy object only apply to that single webrequest, and how could I apply it to a web browser control? Also, how do I edit the config for System.net? – Bob Oct 13 '11 at 04:05
  • EDIT with setting setting proxy on web browser control without affect IE settings. – bryanmac Oct 13 '11 at 04:18
  • Alright, so I read the other post, and some say that its impossible without changing IE settings, except for one post which talks about some code... but how would I implement what he provided? – Bob Oct 13 '11 at 04:23
  • I haven't done that - here's another post in case it points you in the right direction. At that point, your hosting an instance of IE so the most straightforward answer is use the system settings. Outside of that, try this?? http://stackoverflow.com/questions/3464444/how-to-intercept-each-request-of-webbrowser-and-forward-to-a-webproxy – bryanmac Oct 13 '11 at 04:26
  • Alright, I was hoping there would be a way to go about doing so without editing registry/IE settings, but apparently its impossible. Thanks for your help though! – Bob Oct 13 '11 at 04:31
  • nothing is impossible - it just gets harder :) I think those pointers had hints where the harder path may be but you ay be swimming up stream ... – bryanmac Oct 13 '11 at 04:37