Last active
August 29, 2015 14:04
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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