title: How to retrieve CancellationToken from http request on webApi?
body: <p>I'm sending request to server like this via HttpClient:</p>
  
  <pre><code>public async Task GetTest()
  {
      CancellationTokenSource tokenSource = new CancellationTokenSource();
      string url = String.Format($"api/Test/getTest");
  
      HttpResponseMessage response = await _httpClientFactory.HttpClient.GetAsync(url, tokenSource.Token).ConfigureAwait(false);
  
      response.EnsureSuccessStatusCode();
  }
  </code></pre>
  
  <p>On WebApi (Core 2.1) method is like this:</p>
  
  <pre><code>[HttpGet("getTest")]
  public async Task&lt;IActionResult&gt; GetTest(CancellationToken token)
  {
      try
      {
          object test = await _dataService.GetTest(token);
  
          return Ok(test);
      }
      catch (Exception ex)
      {
          this._logger.LogError(ExceptionHelper.ExMessageDeepGet(ex));
          return new InternalServerErrorWithMessageResult(ex);
      }
  }
  </code></pre>
  
  <p>In <code>_dataService.GetTest(token)</code> I do <code>token.ThrowIfCancellationRequested();</code></p>
  
  <p>Problem is that I get new token on webapi, not the one I've send via client so if I stop request (shut down client) before response from api, no exception is thrown..</p>
  
  <p>Any suggestions?</p>