• ashx代码1


    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 }
    文件下载
  • 相关阅读:
    MFC线程(二):线程同步临界区CRITICAL SECTION
    自定义消息
    Visual C++线程同步技术剖析:临界区,时间,信号量,互斥量
    //解析数据函数指针,很爽
    CListCtrl使用方法汇总
    进度条的使用 Progress控件
    CListBOX 用法
    文件操作总结
    CString 十六进制转二进制
    Numpy常用数据结构、数据清洗函数、数据结构series和方法、数据结构dataframe和方法
  • 原文地址:https://www.cnblogs.com/HuShaoyi/p/8456003.html
Copyright © 2020-2023  润新知