views:

372

answers:

2

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

+2  A: 

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.

Justin Grant
cheers mate, this did work, i indeed wanted to get the right proxy server url, read the documentation on msnd and it was decieving! :) thanks
Ayyash
A: 

by making the chages in my web.config m getting error "The underlying connection was closed: Unable to connect to the remote server. " what could be the reason

pp