日期:2014-05-18 浏览次数:20806 次
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e) { bool Authenticated = false; Authenticated = SiteLevelCustomAuthenticationMethod(Login1.UserName, Login1.Password); e.Authenticated = Authenticated; if (Authenticated == true) { Response.Redirect("MainForm.aspx"); } } private bool SiteLevelCustomAuthenticationMethod(string UserName, string Password) { bool boolReturnValue = false; ConnectionStringSettings cs = ConfigurationManager.ConnectionStrings["CS"]; string strConnection = cs.ConnectionString; SqlConnection Connection = new SqlConnection(strConnection); String strSQL = "Select * From 用户"; SqlCommand command = new SqlCommand(strSQL, Connection); SqlDataReader Dr; Connection.Open(); Dr = command.ExecuteReader(); while (Dr.Read()) { if ((UserName == Dr["工号"].ToString()) & (Password == Dr["密码"].ToString())) { boolReturnValue = true; Session["username"] = Dr["姓名"].ToString(); Session["role"] = Dr["角色"].ToString(); } } Connection.Close(); return boolReturnValue;
<?xml version="1.0"?> <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"> <appSettings/> <connectionStrings> <add name="CS" connectionString="Data Source=#######;Initial Catalog=DJS;Persist Security Info=True;User ID=sa;Password=******" providerName="System.Data.SqlClient" /> </connectionStrings> <system.web> <compilation debug="true"> </compilation> <authentication mode="Forms"> <forms name=".FormsAuthCookie" timeout="30" /> </authentication> <authorization> <deny users="?" /> </authorization> </system.web> </configuration>
if ((UserName == Dr["工号"].ToString()) & (Password == Dr["密码"].ToString())) //这应该是与的关系吧 你这是“异或”吧? { boolReturnValue = true; Session["username"] = Dr["姓名"].ToString(); Session["role"] = Dr["角色"].ToString(); }