zoukankan      html  css  js  c++  java
  • Handler

    httphandler就是来处理客户端对服务器端请求的中转站 后缀名是ashx


    案例

    namespace BookShop.Handler
    {
    /// <summary>
    /// BookHandler 的摘要说明
    /// </summary>
    public class BookHandler : IHttpHandler
    {
    public void ProcessRequest(HttpContext context)
    {
    string fileName = context.Request.Url.ToString(); //获取请求的地址
    fileName = fileName.Substring(fileName.LastIndexOf('/') + 1);
    string bookPic = context.Server.MapPath("/images/BookCovers/" + fileName);
    Image book;
    if (File.Exists(bookPic))
    {
    //读取对应的图片
    book = Image.FromFile(bookPic);
    //读取水印图片
    Image water = Image.FromFile(context.Server.MapPath("/images/WaterMark.jpg"));
    //画布
    Graphics g = Graphics.FromImage(book);
    //在画布上❀水印
    g.DrawImage(water, book.Width - water.Width, book.Height - water.Height);
    g.Dispose(); //释放资源
    water.Dispose(); //释放
    
    }
    else
    {
    //如果请求图书不存在,返回默认图片
    book = Image.FromFile(context.Server.MapPath("/Images/default.jpg"));
    }
    context.Response.ContentType = "image/jpeg"; //设置输出格式
    //向客户端输出图片流
    book.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
    book.Dispose(); //释放
    }
    
    public bool IsReusable
    {
    get
    {
    return false;
    }
    }
    }
    }

    handler配置 system.webServer

    <system.webServer>
    <handlers><!--配置handler-->
    <!--type属性需要明确命名空间-->
    <add name="bookWater" verb="*" path="/images/BookCovers/*.jpg" type="BookShop.Handler.BookHandler"/>
    </handlers>
    </system.webServer>

    客户端通过浏览器向服务器发送请求中间由aspnet_isapi.dll 再有Application 再由WebModule 再由WebHandler给向客户端

    配置项中 谁访问了Path中 那么就要去WebModule 中进行处理

  • 相关阅读:
    [转载]苹果推送通知服务
    Lovekey
    大数阶乘的位数
    大明A+B
    大数取余
    A+Bcoming
    大数取余(C++)
    验证角谷猜想
    麦森数(转)
    大数阶乘的位数(C++)
  • 原文地址:https://www.cnblogs.com/ZaraNet/p/9433529.html
Copyright © 2011-2022 走看看