I was wondering what is the best way (if at all possible) to determine on the server side if a given HttpRequest was sent via ajax?
This may or may not help you out, but you can at least determine if the postback is an asynchronous one (meaning that it was likely sent via ajax). You can do this via the following:
if (sm1.IsInAsyncPostBack)
{
//code here
}
The sm1 referenced above would be provided for with this:
<asp:ScriptManager id="sm1" runat="server" />
An XMLHttpRequest appears just like any other browser request. As far as I know, there's no way to distinguish them, unless the XMLHttpRequest is deliberately setting headers to identify itself as such.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With