各位侠客请看:
我要作的是不能通过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!!!
我要作的是不能通过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!!!
没用过.最好改用Session判断啊.
{
try{
Server.Execute("judge.aspx");
}catch(Exception ex)
{}
}
那这是为什么呢?
{
//这里
}
我在main.aspx页中这么作了,还是不行呀
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Server.Execute("judge.aspx");
}
}
protected void Button1_Click(object sender, EventArgs e)
{
this.GridView1.DataSourceID = "SqlDataSource1";
this.GridView1.DataBind();
}