What is it with Devs and Firewalls?

I’ve only found one Twitter client that works properly from behind an Internet proxy. What is it with Devs today? Do they not know that there is a large population out on the Internet that would love to use their programs at work? And that most corporations do not allow direct access to the Internet?

 

So that every .NET Dev out there will know how to incorporate Internet proxy authentication into their code, I thought I would post the following simple steps:

 

1. Add 4 settings to your App.Config file:

 

UseProxy – Boolean, turns on and off the proxy code

ProxyUri – String, the URL to the proxy server formatted as http://proxyserver:port

ProxyUsername – String, the User Name to use to authenticate with the proxy server

ProxyPassword – String, the Password to use to authenticate with the proxy server

 

2. Add the following code to your Get or Post code to create a WebProxy and add it to the WebClient:

 

if (Properties.Settings.Default.UseProxy)
{
    WebProxy proxy = new WebProxy(Properties.Settings.Default.ProxyUri);
    proxy.Credentials = new NetworkCredential(Properties.Settings.Default.ProxyUsername,
                                              Properties.Settings.Default.ProxyPassword);
    client.Proxy = proxy;
}

 

That’s all there is to it! Not hard, pretty simple really, if you think about it. So with four application settings and no more than 7 lines of code, your too can incorporate Internet proxy authentication into your web-based Windows Form or WPF application.

 

 

Leave a Reply