public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; // 在 Handler 里获取 session 要实现 System.Web.SessionState.IRequiresSessionState 接口 int intAdminID = HelperUtility.hasPurviewPage(""); if (context.Request.Form["username"] == null || "".Equals(context.Request.Form["username"].ToString())) { context.Response.Write("POST提交的username不能为空!"); } string strUsername = context.Request.Form["username"].ToString(); if (BllAdmin.hasUsername(strUsername)) { context.Response.Write("用户名已注册!"); } else { context.Response.Write("OK"); } }
protected void btnAdd_Click(object sender, EventArgs e) { if (!HelperUtility.hasPurviewOP("SysAdmin_add")) { string strUrl = "/BackManager/home.aspx"; HelperUtility.showAlert("没有操作权限", strUrl); } string strMsgError = ""; string strUsername = tbUsername.Value.ToString().Trim(); if ("".Equals(strUsername)) { strMsgError += "用户名不能为空!\n"; } if (strUsername.Length < 4 || strUsername.Length > 12) { strMsgError += "用户名长度必须在4 ~ 12之间!\n"; } if (BllAdmin.hasUsername(strUsername)) { strMsgError += "用户名已存在,请取过!\n"; } string strPassword = tbPassword.Value.ToString(); if ("".Equals(strPassword)) { strMsgError += "密码不能为空!\n"; } if (strPassword.Length < 4 || strPassword.Length > 12) { strMsgError += "密码长度必须在4 ~ 12之间!\n"; } string strPassword2 = tbPassword2.Value.ToString(); if ("".Equals(strPassword2)) { strMsgError += "确认密码不能为空!\n"; } if (!strPassword.Equals(strPassword2)) { strMsgError += "两次输入的密码必须相同!\n"; } strPassword = HelperCrypto.encode(strPassword, "DES"); string strRealName = tbRealName.Value.ToString().Trim(); if (strRealName.Length > 6) { strMsgError += "真实姓名长度不能大于6个字符!\n"; } string strMobilePhone = tbMobilePhone.Value.ToString().Trim(); if (!HelperUtility.isMobilePhone(strMobilePhone)) { strMsgError += "手机号码格式不正确!\n"; } if (!"".Equals(strMsgError)) { HelperUtility.showAlert(strMsgError, "add.aspx"); } // 验证完毕,提交数据 ModelAdmin model = new ModelAdmin(); model.username = strUsername; model.password = strPassword; model.real_name = strRealName; model.mobile_phone = strMobilePhone; model.purviews = getSelectedCheckBox(); int intId = BllAdmin.add(model); if (intId > 0) { string strUrl = "list.aspx"; HelperUtility.showAlert("添加成功!", strUrl); } else { string strUrl = "add.aspx"; HelperUtility.showAlert("添加失败,请联系管理员!", strUrl); } }