会话变量
我定义了我的会话变量,在我的 Global.asax
中称为 user
,如下所示
protected void Session_Start(object sender, EventArgs e)
{
Session["idMap"] = "";
Session["user"] = "";
}
我还有一个 asp:Login
在其中设置值loggedIn
事件中的会话变量
protected void lgnMapZone_LoggedIn(object sender, EventArgs e)
{
Session.Abandon();
Session["user"] = lgnMapZone.UserName;
}
我的问题是,当用户进行身份验证时,它会调用 void session_start 并删除我的变量,我该如何解决这个问题?
I defined my session variable, in my Global.asax
called user
like this
protected void Session_Start(object sender, EventArgs e)
{
Session["idMap"] = "";
Session["user"] = "";
}
Also i have a asp:Login
in where i set the value of the session variable in the event of loggedIn
protected void lgnMapZone_LoggedIn(object sender, EventArgs e)
{
Session.Abandon();
Session["user"] = lgnMapZone.UserName;
}
My problem it's that when the users it's autenthicated, the void session_start it's called and erase my variable, how can i solved this??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Session.Abandon()
销毁会话并触发Session_OnEnd
事件。当用户注销而不是登录时,您应该调用此方法。您可能应该调用 Session.Clear(),它只是在登录时从会话对象中删除所有值(内容)。
这将解决您现在遇到的问题。
Session.Abandon()
destroys the session and theSession_OnEnd
event is triggered. You should call this method when the user does a logout instead of log in.You should probably call
Session.Clear()
which just removes all values (content) from the session Object while logging in.This will resolve the issue that you have now.
在 Session_Start 中再次设置变量之前,您可以检查该变量是否已设置。
You could check whether the variable is set or not before you set it again in Session_Start.
简单:
在 Session_Start 内:
Easy:
inside Session_Start: