[英]Session variable gets lost after publishing (works on dev machine)
A quick project I've been asked to knock together doesn't need crazy security, so, I've implemented a simple login screen that checks the Username & PW against the db. 我被要求快速完成一个项目,不需要疯狂的安全性,因此,我实现了一个简单的登录屏幕,该屏幕针对数据库检查用户名和密码。
User u = new User();
if (u.AuthenticateUser(txtUsername.Text, txtPassword.Text))
Session.Add("UserSeshAuthenticated", true);
Response.Redirect("Dashboard.aspx");
All the other pages share a MasterPage and in the Page_Load
event: 所有其他页面共享一个母版页,并在
Page_Load
事件中:
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 all works very well on my development machine, but when I've published it to my server, by the time my MasterPage loads, it has lost the session variables. 所有这些在我的开发机器上都能很好地工作,但是当我将其发布到服务器上时,当我的MasterPage加载时,它已经丢失了会话变量。
Can anyone help ?... I'm supposed to have it live this afternoon & I didn't think I'd run into this problem !!! 有人可以帮忙吗?...我应该在今天下午直播它,我不认为自己会遇到这个问题!!!
Any help appreciated. 任何帮助表示赞赏。 Thanks a lot.
非常感谢。
In your login code, you add "UserSeshAuthenticated" to the session, but not the User object. 在您的登录代码中,将“ UserSeshAuthenticated”添加到会话中,但不添加User对象。 If the function u.AuthenticateUser() adds a copy of itself into the Session, that could be your problem.
如果函数u.AuthenticateUser()将自己的副本添加到会话中,则可能是您的问题。 Try adding that in your result block instead.
尝试将其添加到结果块中。 Like this:
像这样:
User u = new User();
if (u.AuthenticateUser(txtUsername.Text, txtPassword.Text))
{
Session.Add("UserSeshAuthenticated", true);
Session.Add("oUser", u);
Response.Redirect("Dashboard.aspx");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.