views:

120

answers:

1

I am having this really weird issue with downloading files from within ASP.Net MVC (not downloading FROM the app, TO the app) and hope someone can help me out.

This bit of code running in a controller:

       using (var wc = new WebClient())
        {
            var siteText = wc.DownloadString("http://www.google.com");
            return siteText;
        }


This returns the error:

System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 208.67.219.231:80

I have tried tons of other addresses with the same result, although "some" will let me through, but those are on the local network.

Is there a setting that I am missing to allow the website to access external sites?

Just of note, I have tried using an HttpWebRequest and setting the User Agent as well, same errors.

My environment is IIS 7.0 running in the Integrated Managed Pipeline. I have tried changing the identity of the application pool to be a user I can verify that has access to the internet as well.


Update This is also happening with images, and all other file types using either the WebClient or WebRequest.Create(url) methods, but ONLY in an ASP.Net application.

A: 

This exception means that either a firewall or a remote computer is actively blocking your connection attempts.

Rather than looking at permissions/user agents you should investigate the network setup of that server. Can it connect directly to the internet without proxy? Do you have a proxy configured in IE?

Try for example the command line

telnet stackoverflow.com 80

Does it connect or do you get a connection refused as well?

chris166
Turns out we are using a Proxy, admins are blocking us from seeing it though.
Tom Anderson