Skip to content

Instantly share code, notes, and snippets.

@lski
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lski/704b95c89bb43f6c21fe to your computer and use it in GitHub Desktop.
Save lski/704b95c89bb43f6c21fe to your computer and use it in GitHub Desktop.
Really basic method for calculating if a request is an ajax/data request
using System;
namespace Microsoft.Owin {
public static class OwinRequestExt {
/// <summary>
/// Really basic method for calculating if a request is an ajax/data request
/// </summary>
public static bool IsAjaxRequest(this IOwinRequest request) {
if (request == null) {
throw new ArgumentNullException("request");
}
IHeaderDictionary headers = request.Headers;
if (headers != null) {
var contentType = headers["Content-Type"];
if (contentType != null) {
var ct = contentType.ToLowerInvariant();
return (ct == "application/json" || ct == "text/json" || ct == "application/xml" || ct == "text/xml" || headers["X-Requested-With"] == "XMLHttpRequest");
}
}
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment