I would like to have only 1 session for each user. But the system generate new one session when I run ajax query. There were no problems when I tested it on debug mode on my computer. Problems rised only in client site on distributed application.
ASP page:
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<input id="Text1" type="text" /><br />
<asp:Button ID="btn_ASP" runat="server" onclick="btn_ASP_Click" Text="Asp" />
<input id="btn_JS" type="button" value="JS" onclick="GetUsersList();" /><br />
Asp button which generates 'ConnectCount' Session element:
protected void btn_ASP_Click(object sender, EventArgs e)
{
int count;
if (HttpContext.Current.Session["ConnectCount"] == null)
count = 1;
else
count = (int)HttpContext.Current.Session["ConnectCount"] + 1;
HttpContext.Current.Session["ConnectCount"] = count;
TextBox1.Text = count.ToString();
}
Web Service code:
[WebMethod(EnableSession = true)]
[ScriptMethod]
public string Get_UsersList2()
{
int count;
if (HttpContext.Current.Session["ConnectCount"] == null)
count = 1;
else
count = (int)HttpContext.Current.Session["ConnectCount"] + 1;
HttpContext.Current.Session["ConnectCount"] = count;
return count.ToString();
}
Ajax query to Web Service
function GetUsersList() {
$.ajax({
url: '/WbSrv_ACTR.asmx/Get_UsersList2',
type: "POST",
contentType: "application/json; charset=utf-8",
data: '{}',
success: function (data, st) {
if (st == "success") {
if (data.d != "") {
text1.value = data.d;
}
else {
}
}
},
error: function () {
alert("Cannot get list of users");
}
});
}
Code in buttons just adds 1 to Session["ConnectCount"].
So when I click 5 times on Asp button and 1 time on JQ button (on local IIS - testing):
result: asp = 5, jq = 6 (correct)
do the same operations on server IIS 7.5:
result: asp = 5, jq = 1 (incorrect)
Server uses other session. For testing - I've added some elements in Session via ASP button and couldn't find them in Web Service (Session was empty there but SessionID was the same)
Could anyone have solution or workaround?
Web config:
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
<customErrors mode="Off" />
<authorization>
<deny users="?" />
</authorization>
</system.web>
<system.webServer>
<security>
<authentication>
<windowsAuthentication enabled="true" />
<anonymousAuthentication enabled="false" />
</authentication>
</security>
</system.webServer>