大家谁有验证用户登录的基类,最好完整代码贴出,让小弟学习一下!我自己写过一个,不过好像没用,没反应的。谢谢各位咯!

解决方案 »

  1.   

    楼上这个不错,可以借鉴,自己在动动脑经吧~~
    [align=center]********************************************************
    本内容用 CSDN小秘书 回复
    每天回帖即可获得10分可用分!
    ********************************************************[/align]
      

  2.   

    public class BasePage : System.Web.UI.Page  
      {   
      public BasePage()  
      {  
      }  
      protected override void OnInit(EventArgs O)  
      {  
      if (base.Session["UserId"] == null || base.Session["UserId"].ToString().Equals(""))  
      {  
      Response.Redirect("~/Error.aspx");  
      }  
      }  
      }  
    public partial class Error : System.Web.UI.Page  
      {  
      protected void Page_Load(object sender, EventArgs e)  
      {  
      Response.Write(" <script>top.location.href='login.aspx'; </script>");  
      }  
      }  
    或使用ihttphanlder
      

  3.   

    http://www.cnblogs.com/jyk/archive/2008/06/19/1224257.html
      

  4.   

    你的页面在继承下basepage就可以了
      

  5.   

    public partial class Login : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
            }        protected void btnSubmit_Click(object sender, ImageClickEventArgs e)
            {
                if ((this.txtUsername.Text != "") && (this.txtPassword.Text != ""))
                {
                    string userName = this.txtUsername.Text.Trim();
                    string userPwd = this.txtPassword.Text.Trim();
                    Response.Cookies["Username"].Value = this.txtUsername.Text;
                    Response.Cookies["Password"].Value = this.txtPassword.Text;
                    string aidSelect = "select * from emp where emp_name ='" + userName + "' and emp_pwd='" + userPwd + "'";
                    DataTable fileTable = new DataTable();
                    fileTable = DbAccess.GetDS(aidSelect).Tables[0];
                    
                    if (fileTable.Rows.Count > 0)
                    {
                        string roleid = DbAccess.getFieldValue("select Role_id from RolePeopleRela where emp_id = (select emp_id from emp where emp_name ='" + userName + "' and emp_pwd='" + userPwd + "')");
                        Session ["RoleId"] = roleid;
                        Response.Write("<script>alert('欢迎登陆!')</script>");
                        Response.Redirect("Index.aspx");
                    }
                    else
                    {
                        //Response.Write("<script>alert('用户名与密码必须正确才能登陆!')</script>");
                        DbUITool.JsMsg(this.Page, "用户名与密码必须正确才能登陆!");
                        Response.Redirect("Login.aspx");
                    }
                }
                else
                {
                    //Response.Write("<script>alert('用户名与密码不能为空!')</script>");
                    DbUITool.JsMsg(this.Page, "用户名与密码不能为空!");
                }
            }
        }
      

  6.   

    http://topic.csdn.net/u/20091214/13/6cd96ef5-3d18-4255-a440-d16ef6503d37.html#r_61900401
      

  7.   

    记得让页面继承 PageBase 而不是 System.Web.UI.Page