c# - Session get null After login immediately in ASP.NET MVC 5 -
on login assigning values session after login becomes null. set session timeout still doesn't work.
public actionresult login([bind(include = "username, password")] loginmodel loginmodel, string returnurl) { if (modelstate.isvalid) { egov_users egov_users = db.egov_users .where(p => p.usertype.type != "o" && p.username == loginmodel.username) .firstordefault(); if (egov_users == null) { modelstate.addmodelerror("", "invalid username"); return view(); } else { if (egov_users.password != loginmodel.password) { modelstate.addmodelerror("", "invalid password"); return view(); } var logindetail = new logindetails(); logindetail.supplierid = (egov_users.supplierid != null) ? egov_users.supplierid.value : 0; logindetail.userid = egov_users.userid; logindetail.username = egov_users.username; logindetail.firstname = egov_users.firstname; logindetail.lastname = egov_users.lastname; session["userid"] = logindetail.userid; session["supplierid"] = logindetail.supplierid; session["username"] = logindetail.username; session["displayname"] = logindetail.firstname + " " + logindetail.lastname; if (string.isnullorempty(returnurl)) { return redirecttoaction("index", "users"); } } } return redirecttoaction("login", "login"); }
in webconfig have set session timeout well.
wiki
Comments
Post a Comment