0

I have an ASP.NET page that includes some jQuery/javascript.
When the page loads, it does an $.ajax() call (to a different "api.aspx" page) to fetch some data to populate the page. I also run an interval to periodically re-fetch the data to update the UI.

All ajax is performed by the same code.

Both pages are on the same server, no CORS issues.

But here's the strange thing, for which I need help:

  • On my main (AWS EC2) server, the ajax call always returns 200, both on page load and on the interval calls.
  • However, on an IIS/ASP.NET server that we set up ourselves, the 1st ajax call (on page load) always returns HTTP200, then the interval-driven ajax calls always return HTTP404.

I've checked the ajax URLs - they are identical.

Because this works perfectly on the AWS server but not on the server I set up, I suspect that this is due to an IIS and/or ASP.NET server config thing. I've done ajax a zillion times and have never seen this before.

Though I'm an expert developer (on both the C# and browser sides), I'm not expert in the "IT" (server config) side of this.

Has anyone else ever seen such behavior? Any ideas on what IIS/ASP.NET settings might be affecting the reliability of an ajax call?

JotaBe
  • 38,030
  • 8
  • 98
  • 117
dlchambers
  • 3,511
  • 3
  • 29
  • 34
  • Can you post your ajax call code? – Hackerman Feb 02 '16 at 15:13
  • In the browser console window/network tab, can you confirm the 200 call and the 404 calls are absolutely, definitely targetting the same URL? Anything different in the querystring that might affect it (e.g. malforming the URL)? Also do you see the 404 errors being logged on IIS's log files and confirmed they look like they should be hitting the correct page there? – PulseLab Feb 02 '16 at 16:59
  • I've triple-checked that, but will now quadruple-check :) – dlchambers Feb 02 '16 at 21:40

1 Answers1

1

This ended up being caused by a too-long query-string.

I was doing a GET.

The call is doing a UI update and thus sends a list of pre-existing entities to the server so as to only retrieve data for entities that have changed.
It turns out that on the 1st call there were no pre-existing entities, thus the query string was short.

But then on subsequent calls there were many pre-existing entities (fetched by that 1st short-query-string call), thus the query string was l-o-n-g, apparently exceeding either the browser's or the server's allowed length.

So the URL was good, but the URI was bad.
Interesting that a too-long query string causes 404... I learned something new today.

I changed it to a POST (including minor rewiring of the server code to handle either GET or POST) and that solved the problem.

Should have been a POST all along, but somehow in the rush of development that got overlooked, and (more importantly) we didn't do any stress testing re: "what happens when we have lots of entities".

dlchambers
  • 3,511
  • 3
  • 29
  • 34
  • Related: http://stackoverflow.com/questions/27758681/passing-long-querystrings-over-urls-shows-page-not-found-error404 – dlchambers Feb 11 '16 at 18:58
  • And: http://stackoverflow.com/questions/28681366/in-asp-net-mvc-would-a-querystring-too-long-result-in-404-file-not-found-error – dlchambers Feb 11 '16 at 19:00