using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace WebApplication1 { /// <summary> /// Handler1 的摘要说明 /// </summary> public class Handler1 : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string userName = context.Request["userName"]; string password = context.Request["password"]; if(userName=="admin"&&password=="123") { context.Response.Write("登录成功"); } else { context.Response.Write("登录失败!用户名或密码不正确"); } } public bool IsReusable { get { return false; } } } }
1 using System; 2 using System.Collections.Generic; 3 using System.Drawing; 4 using System.Drawing.Imaging; 5 using System.Linq; 6 using System.Web; 7 8 namespace WebApplication1 9 { 10 /// <summary> 11 /// Handler1 的摘要说明 12 /// </summary> 13 public class Handler1 : IHttpHandler 14 { 15 16 public void ProcessRequest(HttpContext context) 17 { 18 context.Response.ContentType = "image/jpeg"; 19 string name = context.Request["name"]; 20 string imgFullPath = context.Server.MapPath("~/PaoNiuZheng.jpg"); 21 using (Image bmp = Bitmap.FromFile(imgFullPath))//读取一张已有的图片 22 using (Graphics g = Graphics.FromImage(bmp))//得到图片的画布 23 using (Font font1 = new Font(FontFamily.GenericSerif, 12))//12号字体 24 using (Font font2 = new Font(FontFamily.GenericSerif, 5))//5号字体 25 { 26 { 27 g.DrawString(name, font1, Brushes.Black, 125, 220);//Font应该被释放 28 g.DrawString(name, font2, Brushes.Black, 309, 55);//Font应该被释放 29 bmp.Save(context.Response.OutputStream, ImageFormat.Jpeg);//图片保存到输出流 30 } 31 } 32 33 } 34 35 public bool IsReusable 36 { 37 get 38 { 39 return false; 40 } 41 } 42 } 43 }
1 using NPOI.HSSF.UserModel; 2 using NPOI.SS.UserModel; 3 using System; 4 using System.Collections.Generic; 5 using System.Data; 6 using System.Drawing; 7 using System.Drawing.Imaging; 8 using System.Linq; 9 using System.Web; 10 11 namespace WebApplication1 12 { 13 /// <summary> 14 /// Handler1 的摘要说明 15 /// </summary> 16 public class Handler1 : IHttpHandler 17 { 18 19 public void ProcessRequest(HttpContext context) 20 { 21 context.Response.ContentType = "application/ms-excel"; 22 context.Response.AddHeader("Content-Disposition", "attachment;filename=" + context.Server.UrlEncode("人员列表.xls")); 23 24 string name = context.Request["name"]; 25 string imgFullPath = context.Server.MapPath("~/PaoNiuZheng.jpg"); 26 IWorkbook workbook = new HSSFWorkbook(); 27 ISheet sheet = workbook.CreateSheet("人员列表"); 28 DataTable dt = SqlHelper.ExecuteQuery("select Id,UserName,Password from T_Users"); 29 30 for(int i=0;i<dt.Rows.Count;i++) 31 { 32 IRow excelRow = sheet.CreateRow(i); 33 DataRow dataRow = dt.Rows[i]; 34 ICell cell0 = excelRow.CreateCell(0); 35 cell0.SetCellValue((string)dataRow["UserName"]); 36 37 ICell cell1 = excelRow.CreateCell(1); 38 cell1.SetCellValue((string)dataRow["Password"]); 39 } 40 workbook.Write(context.Response.OutputStream); 41 42 } 43 44 public bool IsReusable 45 { 46 get 47 { 48 return false; 49 } 50 } 51 } 52 }