Jon
Jon

Reputation: 2509

How would I determine on the server side if a given HttpRequest was sent via ajax?

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?

Upvotes: 3

Views: 179

Answers (3)

Roboblob
Roboblob

Reputation: 1795

Here is similar but more detailed information on this subject:

How to determine whether an Asynchronous Partial Postback has occurred on page?

Upvotes: 1

alex
alex

Reputation: 953

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" />

Upvotes: 2

Tony
Tony

Reputation: 3478

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.

Upvotes: 2

Related Questions