0

I'm having problems making HTTP requests from my MVC.Net Intranet application. I encountered the problem when using the RestSharp library, but have boiled it down to a much simpler repro.

The following code:

using (var client = new WebClient())
{
    var contents = client.DownloadString("http://www.google.com");
}
  • Will run successfully (on my local machine, debugging from Visual Studio 2013) inside a console app.
  • Will run successfully (on my local machine) from within LinqPad
  • Times out (on my local machine, debugging from Visual Studio 2013, hosted with IIS Express) when run from a controller action in a MVC intranet app.

This may be a duplicate of Not able to connect to website URLs from Asp.Net WebApi Action Methods (and is where I got the boiled down proof-of-problem code above) but in my case this is all running locally on my computer and it works fine from a console app.

I've tried various different code snippets, including using HttpClient instead of WebClient:

        using(System.Net.Http.HttpClient c = new System.Net.Http.HttpClient())
        {
            var msg = c.GetAsync("http://www.google.com").Result.Content.ReadAsStringAsync().Result;
        }

But I get the same, or similar results and errors in all cases. For the code above, I eventually get a 'TaskCancelled' exception, with no Inner Exception.

I've also got colleagues to try the same on their own machines, with the same results. I have read some similar questions, where people talk about problems with deadlock due to the SyncronizationContext in ASP applications, but that seems to relate to asynchronous calls. Here, as far as I can tell, everything I am doing is synchronous so I can't see how that applies.

In reality, I'm using the RestSharp library, which I've used to create a client library of my own for talking to the facebook API. I had tested this from a console app test-harness, which worked perfectly, but it all times out when I start using it inside my MVC app.

  • Has anyone seen this before and have any ideas on where I'm going wrong, or what the issue might be?
  • Is it to do with locking / deadlocking?
  • Could it be to do with permissions / proxy? We have quite strict web proxy rules at work, which are obviously configured correctly for my user. Could IIS Express hosting be changing the permissions or the user assigned to the app? The IIS Express service is running with my username at present.

UPDATE

I have tinkered some more and tried accessing an internal company web page instead of an external page (Google). I find that this works immediately - so that suggests strongly that it's to do with permissions or proxy settings.

  • Can anyone explain why this would be different between a console app and a MVC application?

UPDATE 2

I've run Fiddler to check the request and see what was happening to it. When fiddler is running the request succeeds. This makes me think it's some strange permissions issue possibly? As a security measure, our login accounts don't have admin rights, instead we have a separate non-interactive account with admin permissions we can use to run apps that need admin rights, or install software etc. To get fiddler to capture traffic, I have to run it with this account.

Still, the calls work fine with my own normal account from the console app or LinqPad - so I guess my question becomes:

  • For an asp / MVC app locally hosted via IIS Express (Visual Studio Debugging), what user will this be run as, and what differences (if any) would there be to a console app?
Community
  • 1
  • 1
xan
  • 7,440
  • 8
  • 43
  • 65
  • Can you use Fiddler to see where the request ends up? – CodeCaster Nov 24 '14 at 10:32
  • @CodeCaster I've just tried with fiddler, and when it' running, the request succeeds immediately. This is very strange, and leading me to think of permissions issues? For fiddler to work I have to run it with different user credentials (we each have a seperate non-interactive windows user account with admin permissions for installing software etc.) – xan Nov 24 '14 at 10:52
  • Then it most likely is a proxy issue. Check the config answer of [How should I set the default proxy to use default credentials?](http://stackoverflow.com/questions/299940/how-should-i-set-the-default-proxy-to-use-default-credentials). – CodeCaster Nov 24 '14 at 10:54
  • @CodeCaster: Thanks, I'm looking at that now. – xan Nov 24 '14 at 11:07

0 Answers0