我有一个重定向问题? [英] I have a redirect question?

查看:78
本文介绍了我有一个重定向问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为页面制作了重定向页面和代码。在我的登录页面中,我必须重定向链接,我希望用户重定向到。我的问题是,当我尝试重定向到我的重定向页面时,它不会去。所以我更改了我的重定向页面上的代码,并尝试再次与用户登录,然后它转到该页面。为什么我的重定向代码第一次没有工作?为什么当我拿出代码时它才有效?第一个代码是我原来的第二个代码是我改变的代码。



第一个代码:



I am have made a redirect page and code for the page. In my login page I have to redirect link I want the user to redirect to. The question I have is that when I try to redirect to my redirect page it will not go. So I changed the code on my redirect page and tried to login again with a user and it went to that page. Why didn''t my redirect code work the first time? And why did it work when I took out the code? The first code is the original one I had the second is the code I changed.

First code:

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");
    }
}





第二代码:





Second Code:

protected void Page_Load(object sender, EventArgs e)
    {
        
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Session["New"] = null;
        Response.Redirect("Login.aspx");
    }
}

Please Help. 

推荐答案

如评论中所述,您将离开Session [New] = null但更重要的是您的Page_Load未检查IsPostBack所以当点击按钮时,你的page_load代码会在按钮点击代码之前运行。



使用if(!IsPostBack)
As stated in the comments, you are leaving Session["New"] = null but more importantly your Page_Load is not checking for IsPostBack so when the button is clicked, your page_load code runs before your button click code.

Use if (!IsPostBack)


这篇关于我有一个重定向问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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