c# - Session variable gets lost after publishing (works on dev machine) -
a quick project i've been asked knock doesn't need crazy security, so, i've implemented simple login screen checks username & pw against db.
user u = new user(); if (u.authenticateuser(txtusername.text, txtpassword.text)) session.add("userseshauthenticated", true); response.redirect("dashboard.aspx");
all other pages share masterpage , in page_load
event:
if ((session["userseshauthenticated"] == null) || ((bool)session["userseshauthenticated"] == false)) { fw.write("userseshauthenticated has been lost or something"); string path = httpcontext.current.request.url.absolutepath; response.redirect("login.aspx?retpath=" + path); } else { lblloggedinusername.text = session["userseshauthenticated"].tostring(); }
this works on development machine, when i've published server, time masterpage loads, has lost session variables.
can ?... i'm supposed have live afternoon & didn't think i'd run problem !!!
any appreciated. lot.
in login code, add "userseshauthenticated" session, not user object. if function u.authenticateuser() adds copy of session, problem. try adding in result block instead. this:
user u = new user(); if (u.authenticateuser(txtusername.text, txtpassword.text)) { session.add("userseshauthenticated", true); session.add("ouser", u); response.redirect("dashboard.aspx"); }
Comments
Post a Comment