登录和会话帮助!!! [英] Login and Session Help!!!

查看:60
本文介绍了登录和会话帮助!!!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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,


这篇关于登录和会话帮助!!!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆