我有两个控制器Login
和Account
控制器。登录验证后,我将值设置为Session["username"]
并使用 .重定向到Account
控制器的索引页面Response.Redirect("../Account")
。我需要访问Controller页面Session["Username"]
上的值。我在视图上使用但未显示值。index
Account
@Session["Username"]
重定向是否会导致会话变量的处置?
public void LoginVerify(UserModel usermodel)
{
var dbContext = new db_restproEntities(); //class derived from DbContext
var usernames = from username in dbContext.tbl_login select username; //read data
List<tbl_login> users = dbContext.tbl_login.ToList();
bool active = false;
foreach (var x in users)
{
if (x.username == usermodel.username && x.password == usermodel.password)
{
if (x.active == true)
{
active = true;
Session["Message"] = "";
Session["session_username"] = x.username;
Session["status"] = "TRUE";
Session["userid"] = x.user_id;
Response.Redirect("../" + x.role);
}
}
}
Session["Message"] = "Invalid Login Details";
Response.Redirect("../Login");
}