A quick way to check if an HTTP Request is an Ajax request is by examining the X-Requested-With Header value.
Please see below:
bool isAjaxRequest = request.Headers["X-Requested-With"] != null && request.Headers["X-Requested-With"] == "XMLHttpRequest";