全局处理程序
public class WaterMaker:IHttpHandler//新建一个类,实现IHttpHandler接口
{
public bool IsReusable
{
get {
return true;
}
}
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "image/jpeg";
// /images/01.jpg
string imgPath = context.Request.MapPath(context.Request.RawUrl);
string logoPath = context.Request.MapPath("logo.png");
using (Image img = Image.FromFile(imgPath))
{
using (Image logo = Image.FromFile(logoPath))
{
using (Graphics g = Graphics.FromImage(img))
{
g.DrawImage(logo, 0, 0, logo.Width, logo.Height);
img.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
}
}
}
}
<system.webServer>
</system.webServer>