Forcing ASP.Net to use a Proxy to make requests


This is a quick one today. I was recently working with a web application that runs a spider to index content on a bunch of intranet sites. The client was a large company with a very security conscious IT team, that had locked down all intranet access from the web server server in question. Luckily Dot Net supports proxies in a loving fashion, and I'll show you how.

As i just mentioned ASP.Net supports using a proxy for its calls out of the box and this is set very simply in the web.config’s <> section. The great thing is it also allows you to exclude some URL’s from using it just like you would in your internet settings on your desktop – even more powerfully it allows these rules to be set using RegEx! How cool.

The section definition is listed on MSDN here.

I have reproduced it below for your pleasure.

        <!-- add your proxy address etc -->
              bypassonlocal="true" />
        <!-- add you bypass urls or Regex's for them below -->
                <add address="[a-z]+\.diaryofaninja\.com" />