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 knowing if the call was made by a javascript fetch() call. Is there any part of the Request object that I can interrogate to discover this?
For example, if I'm interested in knowing if the caller is a javascript $.ajax call, on the server-side I can call this method:
Request.IsAjaxRequest();
and if it returns true I know that the call was something like this:
$.ajax({
url: '/MyDomain/MyControllerAction',
type: 'GET',
success: function (data) {
doSomething(data);
},
error: function (XMLHttpRequest, ajaxOptions, ex) {
doSomethingElse(XMLHttpRequest, ajaxOptions, ex);
});
Is there something like Request.IsAjaxRequest() I can call or interrogate to discover if the caller was a javascript fetch(), eg a call like this:
fetch('/MyDomain/MyControllerAction')
.then(function (data) {
if(data.ok){
return data.json();
}
})
.then(function (data) {
doSomething(data)
})
.catch(function (error) {
doSomethingElseAgain(error);
});