Link to home
Start Free TrialLog in
Avatar of Tim
Tim

asked on

Data leak on AJAX call return data.

I run an intranet site authenticating using Windows Authentication (the users Windows Login accounts).

Anyhow, My program makes AJAX calls to my C# code behind files and I am having issues with the return data being leaked between users when multiple users make a query at the same time, user 1 may get user 2's data and vice versa.

Can anyone tell me where I am going wrong and how I can improve this. Below is what I am using (omitting some table specific javascript code). The code itself works fine outside of this issue.

UserLookup(IDList)
{
    var strIDs = IDList.split("\n");
    var arrayLength = strIDs.length;

    var HDCount = 0;
    if (strIDs[HDCount] != null && strIDs[HDCount].length >= 7) 
    {
        var HDxmlhttp = new XMLHttpRequest();
        HDxmlhttp.onreadystatechange = function () 
        {
		if (HDxmlhttp.readyState == 4 && HDxmlhttp.status == 200) 
		{
                	var inputdata = HDxmlhttp.responseText;
                    	HDCount++;

                    	if (HDCount < arrayLength) 
			{
				HDxmlhttp.open("POST", "userlookup.aspx/Search", true);
				HDxmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				HDxmlhttp.send("Method=" + encodeURIComponent("Search") + "&ID=" + encodeURIComponent(strIDs[HDCount]));
                    	}
                    	else
                    	{

                    	}      
                }
        }

        HDxmlhttp.open("POST", "userlookup.aspx/Search", true);
        HDxmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        HDxmlhttp.send("Method=" + encodeURIComponent("Search") + "&ID=" + encodeURIComponent(strIDs[HDCount]));
    }
}

Open in new window


Thanks
Avatar of gr8gonzo
gr8gonzo
Flag of United States of America image

An AJAX call isn't responsible for the data returned. If an AJAX call for data returns some other user's data, then that sounds like a problem on the ASP.NET side of things, not the AJAX client-side of thing.

It sounds like maybe the ASP.NET script is doing some juggling of requests (maybe it has a queue that gets processed and is simply returning the first value it gets from the queue instead of looking for the CORRECT response from the queue).
Avatar of Tim
Tim

ASKER

Hi gr8gonzo,

My C# code performs its works then sends back the response to the AJAX callback function as an example:

HttpContext.Current.Response.Write("TEST");
HttpContext.Current.Response.End();

I don't perform any special checks to know who is sending data, I just receive the call on the C# side, process the data sent and return data to it as per the above code.

What would be the correct way to go about this?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Kelvin McDaniel
Kelvin McDaniel
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial