日期:2014-05-17 浏览次数:20688 次
function loginFun() { var userName = document.getElementById("TxtUserName").value; var userSN = document.getElementById("TxtPassword").value; if (userName == "") { alert("请输入账号"); } else if (userSN == "") { alert("请输入密码"); } else { var hRq = createHttpRequest(); //创建ajax对象 hRq.open("POST", "UserLogin.ashx?user=" + userName + "&sn=" + userSN, false); hRq.send(); } }
public class UserLogin1 : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string userName = context.Request["user"]; string userSn = context.Request["sn"]; string connctionStr = ConfigurationManager.AppSettings["DbConnectionString"]; try { using (SqlConnection sqlConn = new SqlConnection(connctionStr)) { sqlConn.Open(); SqlCommand sqlCmd = new SqlCommand("select top 1 * from users where userName like '" + userName + "'",sqlConn); SqlDataReader sqlDR = sqlCmd.ExecuteReader(); if (sqlDR.Read()) { string name = sqlDR["userName"].ToString(); string sn = sqlDR["userSN"].ToString(); string userRight = sqlDR["Edit_right"].ToString(); if (name == userName && userSn == sn) { if (userRight == "false") { } else { context.Response.Redirect("Default.aspx",false); } } else { context.Response.Write("用户名或密码错误!"); } } sqlDR.Close(); } } catch (Exception e) { context.Response.Write(e.Message); } } public bool IsReusable { get { return false; } } } }