title: Why was the web service task canceled and how do I find out?
body: <p>When I'm trying to log in to my website using an online web service I wrote, I don't see anything happening at all...</p>
  
  <p>I should point out that this works 100% when I run everything from localhost.</p>
  
  <p>In my login:</p>
  
  <pre><code>    private async Task DoLogin(string EmailAddress, string Password)
      {
          using (var client = new HttpClient())
          {
              client.BaseAddress = new Uri(ServiceURL);
              client.DefaultRequestHeaders.Accept.Clear();
              client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  
              User u = new User() { EmailAddress = EmailAddress, Password = Password };
  
              HttpResponseMessage response = await client.PostAsJsonAsync("api/user/login", u);
              if (response.IsSuccessStatusCode)
              {
                  u = await response.Content.ReadAsAsync&lt;User&gt;();
                  if (u.Role.RoleName == "Admin")
                  {
                      generateCookie(u);
                  }
                  else
                  {
                      throw new InvalidOperationException("Your user account is not permitted to access this website");
                  }
              }
              else
              {
                  throw new InvalidOperationException("The email address or password you entered is incorrect.");
              }
          }
      }
  </code></pre>
  
  <p>During execution, this doesn't get past the <code>PostAsJsonAsync</code> await although I get a response (as taken from Fiddler):</p>
  
  <blockquote>
    <p>{"Title":"USER LOGIN","Message":"Error actioning request: [ A task was
    canceled.
    ]\r\n","Error":"System.Threading.Tasks.TaskCanceledException: A task
    was canceled.\r\n   at
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
    task)\r\n   at
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
    task)\r\n   at
    System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n   at
    OrtundAdmin.Controllers.HomeController.\u003cDoLogin\u003ed__4.MoveNext()
    in r:\Users\Logan\Documents\Visual Studio
    2013\Projects\Backup\OrtundService\OrtundAdmin\Controllers\HomeController.cs:line
    66\r\n--- End of stack trace from previous location where exception
    was thrown ---\r\n   at
    System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n<br>
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
    task)\r\n   at
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
    task)\r\n   at
    System.Runtime.CompilerServices.TaskAwaiter.GetResult()\r\n   at
    OrtundAdmin.Controllers.HomeController.\u003cLogin\u003ed__0.MoveNext()
    in r:\Users\Logan\Documents\Visual Studio
    2013\Projects\Backup\OrtundService\OrtundAdmin\Controllers\HomeController.cs:line
    38"}</p>
  </blockquote>
  
  <p>This formatting tells me that something went wrong on the service (see the HttpPost below) but it's very vague - "task was canceled". Why? How do I find out?</p>
  
  <pre><code>    [HttpPost]
      [Route("~/api/user/login")]
      public HttpResponseMessage Login([FromBody]User Source)
      {
          try
          {
              User requestedUser = db.Users.Include("Role").FirstOrDefault(x =&gt; x.EmailAddress == Source.EmailAddress);
  
              if (requestedUser != null &amp;&amp; Hashing.ValidatePassword(Source.Password, requestedUser.Password))
              {
                  return Request.CreateResponse(HttpStatusCode.OK, requestedUser);
              }
              return Request.CreateResponse(HttpStatusCode.NotFound, "Incorrect username or password");
          }
          catch (Exception ex)
          {
              return ReportError(ex, "USER LOGIN");
          }
      }
  </code></pre>