A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 丁艳姣 中级黑马   /  2012-10-25 13:39  /  1915 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

我的登录页面的代码是:
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?

评分

参与人数 1技术分 +2 收起 理由
王松老师 + 2

查看全部评分

1 个回复

倒序浏览
你退出的时候,就让他再刷新一下。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马