首页 > 其他 > 详细

ashx代码1

时间:2018-02-20 23:54:40      阅读:303      评论:0      收藏:0      [点我收藏+]
技术分享图片
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 }
文件下载

 

ashx代码1

原文:https://www.cnblogs.com/HuShaoyi/p/8456003.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!