登录和会话帮助!!!

编程入门 行业动态 更新时间:2024-10-26 20:28:12
本文介绍了登录和会话帮助!!!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有点问题。我想知道为什么我登录新会话时不会显示用户名?我有另一台计算机上的代码,我在该计算机上运行调试,我能够登录,标签显示用户名。以下是代码:

I have a little problem. I wanted to know why is it when I login the new session will not display the user name? I have the code on another computer and I ran the debug on that computer and I was able to log in and the Label displayed the username. Here is the code:

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class CEOPage : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (Session["New"] != null) { Label1.Text += Session["New"].ToString(); } else { Response.Redirect("Login.aspx"); } } protected void Button1_Click(object sender, EventArgs e) { Session["New"] = null; Response.Redirect("Login.aspx"); } }

我对代码运行调试并不断重定向回登录。所以我把代码更改为:

I ran the debug on the code and kept getting redirected back to the login. So I changed the code to this:

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class CEOPage : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { Session["New"] = null; if (Session["New"] != null) { Label1.Text += Session["New"].ToString(); } else { Response.Redirect("Login.aspx"); } } }

登录无需重定向回登录页面,但在欢迎页面上标签未显示用户名。我做错了什么,我错过了什么?

The Login works without redirecting back to login page but on the welcome page the label is not showing the user name. What did I do wrong and what am I missing?

推荐答案

Hi Kwesi, 看起来像你需要检查代码的逻辑。以下代码中的逻辑就像您将会话始终设置为null(每次单击按钮后)。我想知道,为什么有,需要使用if条件。 Hi Kwesi, Looks like you need to check the logic of the code. The logic in the below code is like you are setting the session to null always (after every button click). I was wondering, why is there, a need to use the if condition. protected void Button1_Click(object sender, EventArgs e) { Session["New"] = null; if (Session["New"] != null) { Label1.Text += Session["New"].ToString(); } else { Response.Redirect("Login.aspx"); }

在页面加载期间,如果要从登录页面重定向到标签,则可以将会话分配给标签欢迎页面。 (根据Jignesh Khart的评论) 谢谢,

During the page load, you can assign the session to a label if you are redirecting from the Login page to the Welcome page. (As per Jignesh Khart's comment) Thanks,

更多推荐

登录和会话帮助!!!

本文发布于:2023-07-13 03:11:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1099760.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!