3

My AngularJS $http post requests to my C# WebAPI restful service fail on Windows 8.1 in Internet Explorer 11. Firefox and Chrome both work.

Some more details:

  • The IT department says our network has no proxy
  • All 'automatically detect' and 'use proxy' settings are unchecked in all browsers
  • The requests fail to IIS both on my localhost and running the site and service on a local server
  • Enhanced protection mode of IE11 is off
  • The request's connection header is 'keep-alive' (I tried 'close' too and it still failed)
  • Sometimes one request will succeed and only from the second request will everything fail
  • No error is shown - the request in IE's network tab just says 'Pending' and all headers and body are blank
  • I'm using HTTP, not HTTPS
  • I've tried the meta tag 'X-UA-Compatible' IE9 and Edge
  • The requests fail for colleagues using IE11 on their machines too
  • All calls in all browsers work perfectly when Fiddler is running
  • Visual Studio 2013 browser link is turned off (so the SignalRArtery JS file isn't constantly making calls to the server and interfering with testing)

My AngularJS request call looks like this:

var url = UrlService.GetUrlOfApi() + 'Account/SignIn';
var postData = { 'username' : username, 'password' : password };
$http(
{
    'url': url,
    'data': postData,
    'method': 'POST'
})
.success(function (data)
{
     ...

My C# service looks like this:

[RoutePrefix("Account")]
[AllowAnonymous]
public class AccountController : BaseController
{        
    [ResponseType(typeof(SecureResponseModel))]
    [Route("SignIn")]
    [HttpPost]
    public IHttpActionResult SignIn(HttpRequestMessage request)
    {
        try
        {
            var userSignInDetails = GetPostData<AuthenticationRequestMessage>(request);
            var token = _hisManager.AuthenticateUser(userSignInDetails.Username, userSignInDetails.Password);
            return new SignInResponseMessage(token, ApiErrorCode.success, Request);
        }
        catch(APIException e)
        {
            throw;
        }
    }

This is what a failing call looks like in IE11, totally blank:

enter image description here

This is what a successful calls looks like when Fiddler is running: enter image description here

Can anyone recommend any other settings to check or things to try please?

Richard
  • 14,798
  • 21
  • 70
  • 103

1 Answers1

0

I have fixed this. My colleague advised the traditional debugging strategy of getting the simplest case to work - so I made a test post controller web service that worked every call:

enter image description here

I then saw the only difference between this method and the one that failed is the BaseController, which contained these methods:

enter image description here

I then changed the code to this to remove the suspicious looking async and await commands: enter image description here

Everything now works perfectly. But can anyone explain why? In my googling this problem for the past day I've read about IE sending two packets instead of one like other browsers, and about resources being left open interfering with connections. But I don't understand how this await command broke the connection in just one browser.

Richard
  • 14,798
  • 21
  • 70
  • 103
  • 1
    I've no idea how that rewrite fixed it or why only one browser was affected, but you'll find many pages talking about problems reading `request.Content` in Web API with Google. Basically the ApiController may already read the content to bind parameters and after that you can't read the request stream again. – cremor Jan 30 '15 at 11:42