title: How to count calls to ASP.NET Web API POST method
body: <p>Is there any way to count the number of calls to the post method in Web API?</p>
  
  <p>For example: I want to disable user if he 3 times enters  wrong username and password combination.
  So after third call in a row, of the post method of Web API controller I want to do something (for example I will disable user somehow or something else).</p>
  
  <p>How to count this calls to API controller method? Is there any already define property or method for this case?</p>
  
  <p>UPDATE:</p>
  
  <p>This is my Web API method:</p>
  
  <pre><code>[Route("login")]
  public async Task&lt;HttpResponseMessage&gt; LoginUser(Login model)
  {
      using (AuthRepository repo = new AuthRepository())
      {
          Regex rgx = new Regex("[^a-zA-Z0-9 -]");
          string deviceId = rgx.Replace(model.DeviceId, "");
          var request = HttpContext.Current.Request;
          var user = await repo.FindUserAsync(deviceId, model.PIN);
          var tokenServiceUrl = request.Url.GetLeftPart(UriPartial.Authority) + request.ApplicationPath + "/Token";
  
          if (user != null)
          {
              MatrixLogManager.Debug("User " + model.DeviceId + "successfully logged in on MatrixSTS.");
              try
              {
                  using (var client = new HttpClient())
                  {
                      var requestParams = new List&lt;KeyValuePair&lt;string, string&gt;&gt;
                                                  {
                                                      new KeyValuePair&lt;string, string&gt;("grant_type", "password"),
                                                      new KeyValuePair&lt;string, string&gt;("username", deviceId),
                                                      new KeyValuePair&lt;string, string&gt;("password", model.PIN)
                                                  };
  
                      var requestParamsFormUrlEncoded = new FormUrlEncodedContent(requestParams);
                      var tokenServiceResponse = await client.PostAsync(tokenServiceUrl, requestParamsFormUrlEncoded);
                      var responseString = await tokenServiceResponse.Content.ReadAsStringAsync();
                      var responseCode = tokenServiceResponse.StatusCode;
                      var responseMsg = new HttpResponseMessage(responseCode)
                      {
                          Content = new StringContent(responseString, Encoding.UTF8, "application/json")
                      };
  
                      return responseMsg;
                  }
              }
              catch (Exception ex)
              {
                  MatrixLogManager.Error("Error: ", ex);
                  throw ex;
              }
          }
          else
          {
                  //IF LOGIN FAILD I WOULD NEED TO COUNT SOMEHOW THAT ONE CALL WAS UNSUCCESSFUL, AFTER THIRD I WILL BLOCK USER, BUT ONLY IT HE MAKES SAME MISTAKE 3 TIMES IN A ROW. 
                 //Adding simple int counter didn't worked for me.
                  return Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Invalid username or password.");
              }
          }
      }
  </code></pre>