Assuming you have to call from the client to server:
You can insert unique ids to your calls using Math.random()
based generators or libraries.
Or when you load the page, you can throw in the SessionId
from ASP.NET (or retrieve it from cookies), and add that to your request.
So it would look like this:
Server:
[WebMethod]
public static string Hello(string name, string sessionId)
{
return "Hello " + name;
}
Client:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js" type="text/javascript"></script>
<script type ="text/javascript">
function guid() {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
s4() + '-' + s4() + s4() + s4();
}
$(document).ready(function () {
$('#somebutton').click(function () {
var id =
$.ajax({
type: "POST",
url: "SomeController/Hello",
data: "{'name':'" + $('#nametxtbox').val() + "', 'sessionId':'" + guid() + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
alert(msg.d);
}
})
return false;
});
});
</script>