I create session when user Login and use session to check access page, when i check session some time rerun null if i refresh page or navigate to other page the session is not null , it's not about specific page ,it's about method some time return null some time get session value , my method in web service and i call it use javascript
[WebMethod(EnableSession = true)]
public object CheckIfLoggedin()
{
try
{
return new { Result = resultEnum.ok, Records = GetUserID() };
}
catch
{
return new { Result = resultEnum.error };
}
}
private Guid? GetUserID()
{
if (Context.Session["User"] != null)
{
string userid = Context.Session["User"].ToString();
if (userid != "")
return new Guid(userid);
else
return null;
}
else
return null;
}
function CheckIfLoggedin() {
var status = 0;
var ItemCount;
$.ajax({
type: "POST",
url: "../../../../_layouts/15/TripPlannerFrontend/TripPlannerSrv.asmx/CheckIfLoggedin",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
success: function (res) {
if (res.d.Result === 2) {
var userid = res.d.Records;
if (userid == null) {
//
}
else {
//window.location = "TripPlanner.aspx";
var returnurl = GetQueryString("returnurl");
if (returnurl != null && returnurl !== "")
window.location = returnurl;
else
window.location = "TripPlanner.aspx";
}
}
else
console.log("try again");
},
error: function (response) {
console.log("try again");
}
});
};