asp.net页面跳转的问题,高手请进
我做的是用户登录功能,在页面上放了html input控件,用javascript获取用户输入的账号密码再用ajax传递到一个一般处理程序中跟数据库比对,但是一般处理程序在页面跳转的时候总是跳转到程序的网页地址,并显示一个空白的网页,这是怎么回事?高手指教!
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; } } }}