Skip to content Skip to sidebar Skip to footer

From Server, How Recognize Javascript Fetch() Call Was Made (asp.net Mvc)

This is not quite a duplicate; the answer provided below is identical to a comment in the proposed duplicate answer. From inside an asp.net controller action, I'm interested in kno

Solution 1:

From this answer, IsAjaxRequest checks a specific HTTP header that's set by $.ajax. To make IsAjaxRequest return true for fetchset this header when you make your request, like this:

fetch('/MyDomain/MyControllerAction', { headers: { 'X-Requested-With': 'XMLHttpRequest' } })

See MDN for a full list of fetch options.

Post a Comment for "From Server, How Recognize Javascript Fetch() Call Was Made (asp.net Mvc)"