sansan
凉凉的阿玛尼呀还要擦香香.......

配置Web.Config 来验证当前登录,不管运行哪个页面,只要没有登录都会自动跳转到登录Login.aspx页面

Web.Config:

    <system.web>
        <authorization>
            <deny users="?"/>
        </authorization>

      <authentication mode="Forms">
              <forms loginUrl="Login.aspx" timeout="2880" defaultUrl="Default.aspx" />

          </authentication>

       </system.web>

Login.aspx.cs

  

protected void btnLogin_Click(object sender, EventArgs e)
        {

            string userName = txtUserName.Text;
            string userPwd = txtUserPwd.Text;

            UserInfo userObj = userOper.CheckLogin(userName, userPwd);
            if (userObj == null)
                Response.Write("<script>alert('用户名或密码错误!');</script>");
            else
            {
                Session["UserInfo"] = userObj;
               
                FormsAuthentication.SetAuthCookie(userObj.UserName, false);
                Response.Cookies.Add(new HttpCookie("UserName", userObj.UserName));
                Response.Redirect(FormsAuthentication.DefaultUrl);
            }
        }

 

posted on 2010-12-27 17:09  sansan-  阅读(601)  评论(1编辑  收藏  举报