Use below method for check/get session value.
.aspx code
$.ajax({
type: "POST",
url: "PageURL/CheckSession",
data: JSON.stringify({ 'SessionName': 'UserId' }),
contentType: "application/json; charset=utf-8",
datatype: "json",
success: function (result) {
result = result.d;
alert(result);
},
error: function (result) {
alert(result.d);
}
});
c# code
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static string CheckSession(string SessionName)
{
if (HttpContext.Current.Session[SessionName] != null)
{
return Convert.ToString(HttpContext.Current.Session[SessionName]);
}
else {
return "fail";
}
}