When I am behind my company's firewall and using C# to interact with a website I am receiving
System.Net.WebException : The remote server returned an error: (403) Forbidden.
However, I can open Internet Explorer on the very same computer and I do not have an issue accessing the same website. Further, I can switch to my company's "non-firewalled" guest network and I again I do not have an issue accessing the same website using my C# application.
I read in other stackoverflow posts that to enable access through the proxy that I would need to include the following in my project's app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.net>
<defaultProxy useDefaultCredentials="true" />
</system.net>
</configuration>
...but it did not work for me. I receive the same error message.
Here is the code that I am attempting to execute:
var request = (HttpWebRequest) WebRequest.Create(loginUrl);
request.ProtocolVersion = HttpVersion.Version10;
request.Proxy = WebRequest.DefaultWebProxy;
request.UseDefaultCredentials = true;
...and there is further code to handle the response to a POST; but I didn't include it because it doesn't seem germane to solving the proxy issue.
I am pretty much a newbie to this topic. Intuitively it seems that I should be able to piggy-back on Internet Explorers Proxy settings so that my C# application also uses them.
To make things even more confusing for me, I noticed that Internet Explorer is not using a single proxy server, but instead is executing an automatic configuration script. This script has many "if" statements checking to see which proxy ip to use depending on the desired ip address.