I have an ASP MVC controller action.
I’m trying to make a web request
public ActionResult Index()
{
WebRequest request = HttpWebRequest.Create("http://www.example.com");
WebResponse response = request.GetResponse();
string str = response.ToString();
}`
I get a “WebException occured” the remote name could not be resolved: ‘www.example.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?
Try specifying the proxy server explicitly:
You could also set the proxy programatically:
When you set
usesystemdefaulttotrue, the application uses the proxy defined in theInternet Optionsdialog box. When you deploy your application in IIS it usually executes under theNetwork Serviceaccount which has very limited privileges, it doesn’t even have any GUI session so it cannot infer the proxy server.