none
页面跳转问题 RRS feed

  • 问题

  • 请问在这个CallBack函数中怎么才能带Session的跳转到Main.aspx页面,每次执行System.Web.HttpContext.Current.Response.Redirect("Main.aspx");都说未将对象引用设置到对象的实例,怎么解决?(代码已补充完整)
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        TcpClient tcpClient = new TcpClient();
        tcpClient.BeginConnect(IPAddress.Parse("127.0.0.1"), 7777, new AsyncCallback(LoginCallBackF), tcpClient);
    }
    
    public void LoginCallBackF(IAsyncResult ar)
        {
            TcpClient tcpClient = (TcpClient)ar.AsyncState;
            try
            {
                tcpClient.EndConnect(ar);
                NetworkStream netStreamSend = new NetworkStream(tcpClient.Client);
                netStreamSend.BeginWrite(loginInfo, 0, loginInfo.Length, new AsyncCallback(SendCallBackF), netStreamSend);
            }
            catch
            {
                return;
            }
    
            rMsg = ReadFromTcpClient(tcpClient);
    
            try
            {
                if (rMsg[0] == 0)
                {
                    byte[] temp = new byte[8];
                    for (int i = 0; i < 8; i++)
                    {
                        temp[i] = rMsg[i + 1];
                    }
                    string uid = Encoding.UTF8.GetString(temp);
                    Session["UID"] = uid;
                    //Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<Script Language=JavaScript>self.location='Main.aspx');</Script>");
                    System.Web.HttpContext.Current.Response.Redirect("Main.aspx");
                }
                else if (rMsg[0] == 10)
                {
                    Response.Write("<Script Language=JavaScript>alert('用户名不存在或密码错误!');</Script>");
                }
                else if (rMsg[0] == 1)
                {
                    Response.Write("<Script Language=JavaScript>alert('该用户禁止登录!');</Script>");
                }
            }
            catch
            {
                Response.Write("<Script Language=JavaScript>alert('连接不成功,登录失败!');</Script>");
            }
        }



    • 已编辑 Nav7SL 2013年4月10日 2:33
    2013年4月10日 2:01

答案

全部回复