Question

here is the sitution, i am testing on my localhost from my machine at home (no proxy server and windows default firewall) and retrieving api.flickr.com xml file, when I come to work (that uses an ISA server to connect) I get "remote server could not be resolved" so I added these lines to the web.config

<system.net>
  <defaultProxy>
   <proxy
    usesystemdefault="False"
    proxyaddress="http://localhost"
    bypassonlocal="True"
     />
   <bypasslist>
    <add address="[a-z]+\.flickr\.com\.+" />
   </bypasslist>

  </defaultProxy>
 </system.net>

that returns:System.Net.WebException: The remote server returned an error: (404) Not Found. what went wrong? thanks

Was it helpful?

Solution

There are two possible scenarios here:

1: If you are building a client app (e.g. Console or WinForms) and want to access http://localhost using WebClient or HttpWebRequest without any intervening proxies, then bypassonlocal="True" should accomplish this. In other words, your app.config should look like this:

<defaultProxy>
   <proxy
    usesystemdefault="False"
    bypassonlocal="True"
     />
  </defaultProxy>
 </system.net>

2: if, however, you're trying to get your ASP.NET app (running on http://localhost) to be able to correctly resolve URIs either with a proxy or without one, then you'll need to set up proxy info correctly in your web.config (or in machine.config so you won't have to change your app's web.config), so ASP.NET will know that you are running a proxy or not running one. Like this:

Home:

<defaultProxy>
   <proxy
    usesystemdefault="False"
    bypassonlocal="True"
     />
  </defaultProxy>
 </system.net>

Work:

<defaultProxy>
   <proxy
    usesystemdefault="False"
    proxyaddress="http://yourproxyserver:8080"
    bypassonlocal="True"
     />
  </defaultProxy>
 </system.net>

It's also possible to use proxy auto-detection, to pick up settings from the registry, etc. but I've always shied away from those approaches for servers apps... too fragile.

BTW, if you find that things are configured correctly, and you still get the error, the first thing I'd recommend is to code up a quick test which manually sets the proxy before your WebClient/HttpWebRequest call, instead of relying on configuration to do it. Like this:

WebProxy proxyObject = new WebProxy("http://proxyserver:80/",true);
WebClient wc = new WebClient();
wc.Proxy = proxyObject;
string s = wc.DownloadString ("http://www.google.com");

If the requests don't go through your work proxy correctly even when you're using code, even if the proxy is correctly configured in your code, then the proxy itself may be the problem.

OTHER TIPS

In WebClient to download data from local no issues but downloading from internet is problem so configure the following

In your Web.config add below lines and replace your Intenet proxy Address and port

<system.net>
    <defaultProxy useDefaultCredentials="true" enabled="true">
      <proxy usesystemdefault="False" proxyaddress="http://your proxy address:port" bypassonlocal="True" />
    </defaultProxy>
    <settings>
      <servicePointManager expect100Continue="false" />
    </settings>   </system.net>

now your program logic work for downloading content from internet and public URLS.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top