各位侠客请看:
我要作的是不能通过URL直接登录主页(main.aspx)
我建了一个网站,有四个页面judge.apx,login.aspx,loginfail.aspx,main.aspx。在main.aspx中:
我拖入了一个sqldatasource,配置好了数据源;又拖入一个gridview,数据源选择
了sqldatasource,并在代码页中输入:
    protected void Page_Load(object sender, EventArgs e)
    {
        Server.Execute("judge.aspx");
    }
并设置它为起始页面。在login.aspx中:
拖入了两个文本框,一个按钮,在代码页中:
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (this.TextBox1.Text == "admin" && this.TextBox2.Text == "admin")
        {
            Session["login"] = "login";
            Response.Redirect("main.aspx");
        }
    }在judge.aspx中:
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["login"] == null || Session["login"] != "login")
        {
            Response.Redirect("loginfail.aspx");
        }
    }在loginfail.aspx中:
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write("<a href=login.aspx>login</a>");
    }现在运行,没有问题,是不能直接进入main.aspx,需要登录;但如果我把gridview
加上了“启用编辑”,再运行,登录后,点编辑时,就出现“网页错误”,汗!!!而且启用gridview的其它功能也会出现这个问题.
这是为什么呀,急呀,119!!!

解决方案 »

  1.   

    Server.Execute("judge.aspx"); 这样用??
    没用过.最好改用Session判断啊.
      

  2.   

    protected   void   Page_Load(object   sender,   EventArgs   e) 
            { 
                try{
                    Server.Execute("judge.aspx"); 
                   }catch(Exception ex)
                {}
            } 
      

  3.   

    如果把 server.execute()去点就可以用"编辑",这是为什么呢?
      

  4.   

    不用server.execute(),用别的可以么?
      

  5.   

    我又作了一下,添加一个按钮,来到main.aspx页后,点按钮就可以对gridview作一次重新的数据绑定,这样就可以了,
    那这是为什么呢?
      

  6.   

    俗话说的好,加上IsPostBack判断试试
      

  7.   

    编辑就是回发了pageload里的有些代码应该放到if(!IsPostBack)
    {
    //这里
    }
      

  8.   

    各位虾客们:
    我在main.aspx页中这么作了,还是不行呀
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Server.Execute("judge.aspx");
            }
        }
      

  9.   

    这种问题没见过,不过你在main页面中在加入一个按钮,重新进行一次绑定,就可以了:
        protected void Button1_Click(object sender, EventArgs e)
        {
            this.GridView1.DataSourceID = "SqlDataSource1";
            this.GridView1.DataBind();
        }