<%@ WebHandler Language="C#" Class="Load" debug="true"%> using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Configuration; using System.Data; using eMIS; using eMIS.Data; using System.Text; using System.IO; using System.Security.Cryptography; using Newtonsoft.Json; public class Load : IHttpHandler { public void ProcessRequest (HttpContext context) { context.Response.ContentType = "text/plain"; //context.Response.Write("Hello World"); string connectionString = ConfigurationManager.AppSettings["emisdb0"].ToString(); eDbManager manager = new eDbManager(connectionString); eDbOperator dbo = manager.CreateDbOperator(); string username = context.Request["username"]; string pwd=context.Request["password"]; username = DataManager.UrlDecode(username); pwd = DataManager.UrlDecode(pwd); string password= md5(pwd); string sql = "select * from com_yhb where login = '" + username + "' and password = '" + password + "'"; DataTable table = dbo.ExecuteTable(sql); if (table.Rows.Count > 0) { //LoginManager lm = new LoginManager(context); //lm.Login(table.Rows[0]["ID"].ToString()); context.Response.Write("OK|"+table.Rows[0]["XingMing"].ToString()+"|"+table.Rows[0]["ID"].ToString()); } else { context.Response.Write("NOOK|ERR"); } context.Response.ContentType = "application/html"; context.Response.ContentEncoding = System.Text.Encoding.UTF8; context.Response.End(); } private String md5(String s) { MD5 md5 = new MD5CryptoServiceProvider(); byte[] bytes = System.Text.Encoding.UTF8.GetBytes(s); bytes = md5.ComputeHash(bytes); md5.Clear(); string ret = ""; for (int i = 0; i < bytes.Length; i++) { ret += Convert.ToString(bytes[i], 16).PadLeft(2, '0'); } return ret.PadLeft(32, '0').ToUpper(); } public bool IsReusable { get { return false; } } } public class JsonHelper { /// /// 将对象序列化为JSON格式 /// /// 对象 /// json字符串 public static string SerializeObject(object o) { string json = JsonConvert.SerializeObject(o); return json; } /// /// 解析JSON字符串生成对象实体 /// /// 对象类型 /// json字符串(eg.{"ID":"112","Name":"石子儿"}) /// 对象实体 public static T DeserializeJsonToObject(string json) where T : class { JsonSerializer serializer = new JsonSerializer(); StringReader sr = new StringReader(json); object o = serializer.Deserialize(new JsonTextReader(sr), typeof(T)); T t = o as T; return t; } /// /// 解析JSON数组生成对象实体集合 /// /// 对象类型 /// json数组字符串(eg.[{"ID":"112","Name":"石子儿"}]) /// 对象实体集合 public static List DeserializeJsonToList(string json) where T : class { JsonSerializer serializer = new JsonSerializer(); StringReader sr = new StringReader(json); object o = serializer.Deserialize(new JsonTextReader(sr), typeof(List)); List list = o as List; return list; } /// /// 反序列化JSON到给定的匿名对象. /// /// 匿名对象类型 /// json字符串 /// 匿名对象 /// 匿名对象 public static T DeserializeAnonymousType(string json, T anonymousTypeObject) { T t = JsonConvert.DeserializeAnonymousType(json, anonymousTypeObject); return t; } }