我的登录页面的代码是:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace exam
{
public partial class login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnOk_Click(object sender, EventArgs e)
{
string uid = this.txtuid.Text.ToString();
string pwd = this.txtpwd.Text.ToString();
if (test(uid, pwd))
{
Session["step"] = uid;
Response.Redirect("houtai.aspx");
}
else {
Response.Write("<script>alert('用户名或密码错误!')</script>");
}
}
//检测用户名的函数
public bool test(string uid, string pwd)
{
SqlCommand cmd = DB.createSqlcommand("select count(*) from guanli where uid='"+uid+"' and pwd='"+pwd+"'");
if (Convert.ToInt32(cmd.ExecuteScalar()) == 1)
{
return true;
}
else {
return false;
}
}
}
}
后台首页的代码是:using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace exam
{
public partial class houtai : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Convert.ToString(Session["step"]) == "")
{
Response.Write("<script>alert('你无权访问该页面!');window.location.href='login.aspx';</script>");
}
if (!IsPostBack)
{
dataBinder();
}
}
public void dataBinder()
{
SqlCommand cmd = DB.createSqlcommand("select * from exam");
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds, "exam");
PagedDataSource pds = new PagedDataSource();
pds.DataSource = ds.Tables[0].DefaultView;
pds.AllowPaging = true;
pds.PageSize = 10;
this.DataList1.DataSource = pds;
this.DataList1.DataBind();
}
protected void btnAdd_Click(object sender, EventArgs e)
{
Response.Redirect("add.aspx");
}
protected void Button1_Click(object sender, EventArgs e)
{
Session["step"] = "";
Response.Write("<script>alert('成功退出!');window.location.href='Default.aspx';</script>");
}
}
}
后台首页有个按钮“退出管理”,当我点击后回到登录页面,但当我再次在地址栏中输入后台首页的网址,依然能访问,只有当我刷新后台页面后,才不能再访问,奇怪的是,我在点击“退出管理”后,其他后台页面立即不能访问,算正常。我在想,是不是有“退出管理”的页面有什么特殊的,不能立即清除session?
|