protected void Page_Load(object sender, EventArgs e) { /*从session里获取用户,没有的话用cookie获取用户,否则跳转*/ if (Session["USER"] != null) { usr = (User)Session["USER"]; } else { string username = (Request.Cookies["username"] != null)?Request.Cookies["username"].Value.ToString().Trim():""; if (username != "") { usr = UserGet.GetFeature(username); Session["USER"] = usr; } if (usr == null) { Response.Redirect("../Usr/UsrLogin.htm"); Response.Flush(); Response.End(); } } if (usr.Privilege < 0) { Response.Write("您没有后台管理权限!"); Response.Flush(); Response.End(); } else { page0.InnerHtml = "欢迎您!" + usr.Name; } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "application/json"; string method = context.Request["method"].ToString().Trim().ToLower(); string usrid = string.Empty; string type = context.Request["type"].ToString().Trim().ToLower(); string labelid = string.Empty; string title = string.Empty; string content = string.Empty; User usr = (context.Session["USER"] != null) ? (User)context.Session["USER"] : null; if (usr == null) { string username = (context.Request.Cookies["username"] != null) ? context.Request.Cookies["username"].ToString().Trim() : ""; if (username != "") { usr = UserGet.GetFeature(username); } } if (usr == null) { context.Response.Write("{\"status\":\"fail\",\"message\":\"用户没登录\"}"); context.Response.Flush(); context.Response.End(); } else { if (usr.Privilege == 0) { usrid = "%"; } else { usrid = usr.Id; } } switch (method) { case "add": labelid = Guid.NewGuid().ToString(); string geometry = context.Request["geometry"].ToString().Trim(); title = context.Request["title"].ToString().Trim(); content = context.Request["content"].ToString().Trim(); if (LabelAdd.AddFeature(type, labelid, usrid, geometry, title, content)) { context.Response.Write("{\"status\":\"success\"}"); } else { context.Response.Write("{\"status\":\"fail\"}"); } break; case "get": int page = Int32.Parse(context.Request["page"].ToString()); int size = Int32.Parse(context.Request["size"].ToString()); context.Response.Write(LabelGet.GetFeature(type, usrid, size, page)); break; case "del": labelid = context.Request["labelid"].ToString().Trim(); if (LabelDel.DelFeature(labelid)) { context.Response.Write("{\"status\":\"success\"}"); } else { context.Response.Write("{\"status\":\"fail\"}"); } break; case "edit": labelid = context.Request["labelid"].ToString().Trim(); title = context.Request["title"].ToString().Trim(); content = context.Request["content"].ToString().Trim(); if (LabelEdit.EditFeature(labelid, title, content)) { context.Response.Write("{\"status\":\"success\"}"); } else { context.Response.Write("{\"status\":\"fail\"}"); } break; } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "application/json"; string method = context.Request["method"].ToString().Trim().ToLower(); string usrid = string.Empty; string usrname = string.Empty; string password = string.Empty; User usr = null; switch (method) { case "add": usrid = Guid.NewGuid().ToString(); usrname = context.Request["usrname"].ToString().Trim(); password = context.Request["password"].ToString().Trim(); int privilege = 1; if (UserAdd.AddFeature(usrid, usrname, password, privilege)) { context.Response.Write("{\"status\":\"success\"}"); } else { context.Response.Write("{\"status\":\"fail\"}"); } break; case "chk": usrname = context.Request["usrname"].ToString().Trim(); if (UserGet.GetFeature(usrname) == null) { context.Response.Write("{\"status\":\"success\"}"); } else { context.Response.Write("{\"status\":\"fail\"}"); } break; case "login": usrname = context.Request["usrname"].ToString().Trim(); password = context.Request["password"].ToString().Trim(); usr = UserGet.GetFeature(usrname); if (usr != null) { if (usr.Password == password) { context.Session.Timeout = 60; context.Session.Add("USER", usr); context.Response.Write("{\"status\":\"success\",\"usrid\":\"" + usr.Id + "\",\"usrname\":\"" + usr.Name + "\"}"); } else { context.Response.Write("{\"status\":\"fail\",\"message\":\"密码错误\"}"); } } else { context.Response.Write("{\"status\":\"fail\",\"message\":\"用户名不存在\"}"); } break; case "logout": break; } }