title: ASP.NET Web API keeps returning the same results even with different input
body: <p>Please note that I have a math library that performs calculations, and when I unit test the library the values returned are correct.</p>
  
  <p>Then I call this library from a function in my Web API application:</p>
  
  <pre><code>    private readonly ICalcContext _context;
      private static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();
      private readonly MemoryCache _memCache = MemoryCache.Default;
  
      public CalcRepository(ICalcContext context)
      {
          _context = context;
      }
  
      public async Task&lt;double[]&gt; GetCalculationAsync(string username, string password, int corporationId, double latitude,
          double longitude, double depth, bool includeWellRuns = false)
      {
          double[] results = null;
  
              Calculation calc = _context.Calculations.FirstOrDefault(e =&gt; e.CorporationId == corporationId);
              if (calc == null) calc = new Calculation();
              var user = _context.MyCalcs.FirstOrDefault(e =&gt; e.UserName == username);
              if (user?.LicenseKey == password)
              {
                  results = MyMathLibrary.MyCalculationFunction(latitude, longitude, depth, DateTime.Now.Day,
                      DateTime.Now.Month, DateTime.Now.Year, DateTime.Now.Year, calc.UseGeoid, calc.UseDecimalYear);
                  calc.Value1  = Convert.ToString(results[0]);
                  calc.Value2 = Convert.ToString(results[1]);
                  calc.CorporationId = corporationId;
                  if (String.IsNullOrEmpty(calc.Username)) calc.Username = username;
                  if (String.IsNullOrEmpty(calc.Password)) calc.Username = password;
                  _context.Calculations.AddOrUpdate(calc);
                  await SaveChangesAsync();
  
                  CacheHandling(calc);
              }
  
          return results;
      }
  
      private void CacheHandling(Calculation calc)
      {
          var res = _memCache.Get("calc");
          if (res != null)
          {
              //This is to remove the MemoryCache - start
              if (_memCache.Contains("calc"))
              {
                  _memCache.Remove("calc");
              }
          }
          else
          {
              _memCache.Add("calc", calc, DateTimeOffset.UtcNow.AddSeconds(30));
          }
      }
  </code></pre>
  
  <p>Here is my controller function:</p>
  
  <pre><code>    [Route("{username}/{password}/{latitude}/{longitude}/{depth}/{corporationId}")]
      public async Task&lt;IHttpActionResult&gt; Get(string username, double latitude,
      double longitude, double depth, int corporationId)
      {
          try
          {
              var result = await _repository.GetCalculationAsync(username, password, corporationId, latitude, longitude, depth);
              if (result == null) return NotFound();
  
              // Mapping
              // This centralizes all of the config
              var mappedResult = _mapper.Map&lt;IEnumerable&lt;CalculationModel&gt;&gt;(result);
  
              return Ok(mappedResult);
          }
          catch (Exception ex)
          {
              Logger.Error(ex);
  
              // Be careful about returning exception here
              return InternalServerError();
          }
      }
  </code></pre>
  
  <p>The problem is that every time I call the Web API function through the web 
  browser client, the same values show up in my web browser.</p>
  
  <p>Here is one sample input URL:
   <a href="http://localhost:6600/api/calculations/mycompany&amp;mypassword&amp;34.123478&amp;-115.123478&amp;2/" rel="nofollow noreferrer">http://localhost:6600/api/calculations/mycompany&amp;mypassword&amp;34.123478&amp;-115.123478&amp;2/</a></p>
  
  <p>Then here is a second URL I send which should cause new values to show up in the web browser client, but doesn't for some reason:</p>
  
  <p><a href="http://localhost:6600/api/calculations/mycompany&amp;mypassword&amp;10.123478&amp;-100.123478&amp;2/" rel="nofollow noreferrer">http://localhost:6600/api/calculations/mycompany&amp;mypassword&amp;10.123478&amp;-100.123478&amp;2/</a></p>
  
  <p>I have even tried clearing the cache, but if I run the function call with different input values it returns the same values to the web client.</p>
  
  <p>The time it worked to give the new updated values is when I changed form using Chrome as the web browser client to using Firefox.</p>
  
  <p>Here are some websites I have checked but am not sure how I can apply this to my situation:</p>
  
  <p><a href="https://stackoverflow.com/questions/4183270/how-to-clear-memorycache/22388943#22388943">How to clear MemoryCache?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/56315930/how-to-clear-memorycache-in-asp-net-core">How to clear MemoryCache in ASP.NET Core?</a></p>
  
  <p><a href="https://www.codeproject.com/Articles/1087902/Caching-in-Web-API" rel="nofollow noreferrer">https://www.codeproject.com/Articles/1087902/Caching-in-Web-API</a></p>
  
  <p><a href="https://stackoverflow.com/questions/23453977/what-is-the-difference-between-preservereferenceshandling-and-referenceloophandl">What is the difference between PreserveReferencesHandling and ReferenceLoopHandling in Json.Net?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/41895785/how-to-reset-serialization-after-each-web-api-call-c-sharp">How to reset serialization after each web api call : C#</a></p>
  
  <p>So could anyone please explain why the WebAPI/web client are showing the same values, even when I clear the cache?  Do I need to clear something in "IIS Express" somehow?  What am I missing?  This is basically the first Web API I have ever built.  TIA.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Thanks for the suggestions <a href="https://stackoverflow.com/users/884561/kenneth-k">@Kenneth K</a>.</p>
  
  <p>This is what I see in Postman so it looks like the controller is being hit:</p>
  
  <p><a href="https://i.stack.imgur.com/yohmU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yohmU.png" alt="enter image description here"></a></p>
  
  <p><strong>UPDATE 2:</strong></p>
  
  <p>Thanks for the suggestion, <a href="https://stackoverflow.com/users/2611237/andrei-dragotoniu">@Andrei Dragotoniu</a></p>
  
  <p>Please note that I have now published the Web API to the IIS on the virtual machine.  When I call it, I use this URL with the parameter names as you suggested and in Postman it appears to work:</p>
  
  <p><a href="http://myserver.westus2.cloudapp.azure.com/EddiToolsAPI/api/calculations?username=mycompany&amp;password=mypassword&amp;latitude=34.123478&amp;longitude=115.123478&amp;depth=2&amp;corporationId=2/" rel="nofollow noreferrer">http://myserver.westus2.cloudapp.azure.com/EddiToolsAPI/api/calculations?username=mycompany&amp;password=mypassword&amp;latitude=34.123478&amp;longitude=115.123478&amp;depth=2&amp;corporationId=2/</a></p>
  
  <p>Yes, of course I can use the headers to store the password once I get the basic functionality working.  According to Postman, it appears to connect, but I've have changed the CalcController to add a new record every time it is called by changing to <code>_context.Calculations.Add(calc)</code>, and even when I use Postman to execute the URL it doesn't appear to actually execute this <code>_context.Calculations.Add(calc)</code> portion because I see no new records added to the database, so I'm not sure what to do next.  Any ideas?</p>
  
  <pre><code>    public async Task&lt;double[]&gt; GetCalculationAsync(string username, string password, int corporationId, double latitude,
          double longitude, double depth, bool includeWellRuns = false)
      {
          double[] results = null;
  
          try
          {
              var calc = new Calculation();
              var user = _context.MyCalcs.FirstOrDefault(e =&gt; e.UserName == username);
              if (user?.LicenseKey == password)
              {
                  results = MyMathLibrary.MyCalculationFunction(latitude, longitude, depth, DateTime.Now.Day,
                      DateTime.Now.Month, DateTime.Now.Year, DateTime.Now.Year, calc.UseGeoid, calc.UseDecimalYear);
                  calc.Declination  = Convert.ToString(results[0]);
                  calc.Inclination = Convert.ToString(results[1]);
                  calc.TotalField = Convert.ToString(results[2]);
                  calc.CorporationId = corporationId;
                  if (String.IsNullOrEmpty(calc.Username)) calc.Username = username;
                  if (String.IsNullOrEmpty(calc.Password)) calc.Password = password;
                  _context.Calculations.Add(calc);
                  await SaveChangesAsync();
  
                  //CacheHandling(calc);
              }
  
          }
          catch (Exception ex)
          {
              Logger.Error(ex);
              throw;
          }
  
          return results;
      }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/iJG8S.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iJG8S.png" alt="enter image description here"></a></p>