我的用户管理界面,用session判断用户是否登录,如果未登录则弹出提示,点击跳转其他页面。但是我发现每次虽然判断了  但是页面内的内容也给加载出来了。  我现在想只弹出对话框,而不加载页面内的内容该怎么办. 代码如下: protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["user"] != null)
        {
            int id = (int)Session["user"];
            Entity.Login m = DAL.Common.Get<Entity.Login>(id);
            this.Label1.Text = m.cishu.ToString();
            this.Label2.Text = DAL.fangchan.GetCountf(id).ToString();
        }
        else
        {
            Page.RegisterStartupScript("ti", "<script>alert('请登录!');window.location.href='Default.aspx'</script>");
        }
    }我个人感觉判断不应该放在pageload里,但是又不知道放那。  请各位大大们指点

解决方案 »

  1.   

    protected void Page_Load(object sender, EventArgs e) 
        { 
            if (Session["user"] != null) 
            { 
                int id = (int)Session["user"]; 
                Entity.Login m = DAL.Common.Get <Entity.Login>(id); 
                this.Label1.Text = m.cishu.ToString(); 
                this.Label2.Text = DAL.fangchan.GetCountf(id).ToString(); 
            } 
            else 
            { 
                Response.Write("<script>alert('请登录!');window.location.href='Default.aspx' </script>"); 
                Response.End();
            } 
        } 
      

  2.   

    1楼的很简单,楼主也可以在web.config中配置一些信息。