<authentication mode="Forms"> <forms name="auth" loginUrl="login.aspx" protection="All"> <credentials passwordFormat="Clear"> <user name="admin" password="admin"/> </credentials> </forms> </authentication> <authorization> <deny users="?"></deny> </authorization>
protected void btnLogin_Click(object sender, EventArgs e) { if (System.Web.Security.FormsAuthentication.Authenticate(txtUserName.Text, txtUserPwd.Text)) { System.Web.Security.FormsAuthentication.SetAuthCookie(txtUserName.Text, false); Response.Redirect("default.aspx"); // System.Web.Security.FormsAuthentication.RedirectFromLoginPage(txtUserName.Text,false); } else { Response.Write("用户不合法"); } }
当只有少量人使用此网站时,只需要在web.config中配置用户,不需要连接数据库。
posted on 2010-05-20 15:18 java课程设计 阅读(164) 评论(0) 收藏 举报