1、httphandler
實(shí)例1:通過(guò)生成一張動(dòng)態(tài)圖片輸出客戶(hù)端的IP地址、操作系統(tǒng)類(lèi)型、瀏覽器類(lèi)型
using System;
using System.Web;
public class visitor : IHttpHandler {
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "image/JPEG";
using (System.Drawing.Bitmap bitImage = new System.Drawing.Bitmap(330, 300))
{
//設(shè)置畫(huà)布
using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitImage))
{
//IP
g.DrawString("IP:" + context.Request.UserHostAddress, new System.Drawing.Font("宋體", 20), System.Drawing.Brushes.Red, new System.Drawing.PointF(0, 0));
//操作系統(tǒng)
g.DrawString("操作系統(tǒng):" + context.Request.Browser.Platform, new System.Drawing.Font("宋體", 20), System.Drawing.Brushes.Red, new System.Drawing.PointF(0, 50));
//瀏覽器
g.DrawString("瀏覽器:" + context.Request.Browser.Type, new System.Drawing.Font("宋體", 20), System.Drawing.Brushes.Red, new System.Drawing.PointF(0, 100));
}
//保存到輸出流中
bitImage.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
}
}
public bool IsReusable {
get {
return false;
}
}
}
html代碼:a href="dowload.ashx">下載/a>
using System;
using System.Web;
public class dowload : IHttpHandler {
public void ProcessRequest(HttpContext context)
{
string fileName = HttpUtility.UrlEncode("悲劇.jpg");
context.Response.ContentType = "image/JPEG";
//打開(kāi)附件對(duì)話(huà)框 報(bào)文頭header和設(shè)置它的值
context.Response.AddHeader("Content-Disposition", "attachment:filename=" + fileName);
context.Response.WriteFile("蘋(píng)果.jpg");
}
public bool IsReusable {
get {
return false;
}
}
}
標(biāo)簽:百色 新鄉(xiāng) 周口 朝陽(yáng) 臺(tái)州 朔州 喀什 洛陽(yáng)
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《ASP.NET筆記之 Httphandler的操作詳解》,本文關(guān)鍵詞 ASP.NET,筆記,之,Httphandler,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。