views:

38

answers:

1

I have an ASP MVC controller action. I'm trying to make a web request

public ActionResult Index()
{
   WebRequest request = HttpWebRequest.Create("http://www.some-internet-address.com");
   WebResponse response = request.GetResponse();
   string str =  response.ToString();
}`

I get a "WebException occured" the remote name could not be resolved: 'www.some-internet-address.com'

If I start Fiddler, then the webrequest works.

I tried adding:

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

to Web.config (with and without hte bypassonlocal) and it still doesn't work.

Any suggestions?

A: 

Try specifying the proxy server explicitly:

<system.net>
    <defaultProxy>
        <proxy proxyaddress="http://proxy.yourcompany.com:80" />
    </defaultProxy>
</system.net>

You could also set the proxy programatically:

request.Proxy = new WebProxy("http://proxy.yourcompany.com:80", true);

When you set usesystemdefault to true, the application uses the proxy defined in the Internet Options dialog box. When you deploy your application in IIS it usually executes under the Network Service account which has very limited privileges, it doesn't even have any GUI session so it cannot infer the proxy server.

Darin Dimitrov