473,406 Members | 2,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Detect xmlhttprequest call?!

Hello,

In the current application we have several httpmodules to process pages,
and we have several pages with calls directly through the XMLHttpRequest.
Now the requiremens is to detect the calls through the XMLHttpRequest and
apply addional actions in httpmodule for these types of call.

Because they dont use ASP.NET AJAX for this I cant use ScriptManager.IsInAsyncPostBack.
Everything what comes into my my how to catch these calls is check CurrentContext.Request.ContentType
for the string entry which is set like
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

before making XMLHttpRequest call. If !(string.IsNullOrEmpty(CurrentContext.Request.Cont entType))
then we have XMLHttpRequest call.

I wonder if there are others way to check if call made via XMLHttpRequest?!

---
WBR,
Michael Nemtsev [Microsoft MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo
Jul 25 '08 #1
2 2421
Hi Michael,

Use Headers collection to identify request comes from a cetrain source.
That's the way Microsoft AJAX does it:
Headers collection:

[0] "Cache-Control" string
[1] "Connection" string
[2] "Content-Length" string
[3] "Content-Type" string
[4] "Accept" string
[5] "Accept-Encoding" string
[6] "Accept-Language" string
[7] "Host" string
[8] "Referer" string
[9] "User-Agent" string
[10] "x-microsoftajax" string <-- AJAX
because you are in control what you put into headers when issueing request
through XMLHttpRequest.

HTH
--
Milosz
"Michael Nemtsev [MVP]" wrote:
Hello,

In the current application we have several httpmodules to process pages,
and we have several pages with calls directly through the XMLHttpRequest.
Now the requiremens is to detect the calls through the XMLHttpRequest and
apply addional actions in httpmodule for these types of call.

Because they dont use ASP.NET AJAX for this I cant use ScriptManager.IsInAsyncPostBack.
Everything what comes into my my how to catch these calls is check CurrentContext.Request.ContentType
for the string entry which is set like
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

before making XMLHttpRequest call. If !(string.IsNullOrEmpty(CurrentContext.Request.Cont entType))
then we have XMLHttpRequest call.

I wonder if there are others way to check if call made via XMLHttpRequest?!

---
WBR,
Michael Nemtsev [Microsoft MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo
Jul 25 '08 #2
"Michael Nemtsev [MVP]" <ne*****@msn.comwrote in message
news:90**************************@msnews.microsoft .com...
Hello,

In the current application we have several httpmodules to process pages,
and we have several pages with calls directly through the XMLHttpRequest.
Now the requiremens is to detect the calls through the XMLHttpRequest and
apply addional actions in httpmodule for these types of call.

Because they dont use ASP.NET AJAX for this I cant use
ScriptManager.IsInAsyncPostBack.
Everything what comes into my my how to catch these calls is check
CurrentContext.Request.ContentType
for the string entry which is set like
request.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded");
>
before making XMLHttpRequest call. If
!(string.IsNullOrEmpty(CurrentContext.Request.Cont entType))
then we have XMLHttpRequest call.

I wonder if there are others way to check if call made via
XMLHttpRequest?!
>
Its not possible to guarantee that the request is coming from XMLHttpRequest
unless there is some help from the client side. You are using a pattern of
usage which you hope is not also created in normal use of your app. Unless
you are prepared to change they way the clientside makes these requests
(and that assumes you have control over that) then your approach is probably
the only one available to you.
AJAX adds a header to specifically identify the request as has already been
pointed out.
--
Anthony Jones - MVP ASP/ASP.NET
Jul 26 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Gaz | last post by:
In Internet Explorer 6 I'm having a problem with the httprequest object. I use it to call a webservice and display the result in the readystate event handler. This works the first time I call it...
10
by: Matt Kruse | last post by:
I'm aware of the circular reference memory leak problem with IE/closures. I'm not sure exactly how to resolve it in this situation. Also, Firefox appears to grow its memory size with the same code....
42
by: Greg | last post by:
Hi, I've designed a bookmark in Ajax / PHP that I will put soon on sourceforge.net. But I've got an very tricky bug. I try it on some computers with Internet Explorer/Windows, Firefox...
1
by: vikas.khengare | last post by:
Hi Friends.... I have AJAX code which giving "Permission denied to call method XMLHttpRequest.open" error. This error fired by FireFox 1.0 and IE 6 and with Tomacat 5.x. This code work very...
1
by: libsfan01 | last post by:
Hi all Can anyone explain the relationship between SOAP and XMLHttpRequest in Javascript? What actually is SOAP? and how does it relate to the process of transferring data client-side through...
5
by: Peter Michaux | last post by:
Hi, The FAQ correctly says the following: "Mozilla (NN6.2+, Firefox, Ice Weasle etc), Opera 7.6+, Safari1.2+, the Windows version of IE versions 5+, and some other browsers provide the XML...
1
by: Charlie | last post by:
I am trying to make an XMLHttpRequest which violates the default "same- origin"policy in Firefox. I checked the archives and found a method that should work but it does not. Below is the test code...
1
by: geevaa | last post by:
http://www.phpbuilder.com/columns/kassemi20050606.php3 XMLHttpRequest and AJAX for PHP programmers James Kassemi Introduction: Although the concept isn't entirely new, XMLHttpRequest...
1
by: shotokan99 | last post by:
hi, i wanted to check if the url is existing using xmlhttprequest. my browser is firefox. the code goes like this: window.onload=ini var xr= new XMLHttpRequest(); function ini(){...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.