濮阳杆衣贸易有限公司

主頁 > 知識庫 > ASP.NET筆記之 Httphandler的操作詳解

ASP.NET筆記之 Httphandler的操作詳解

熱門標(biāo)簽:廈門四川外呼系統(tǒng) 泰州手機(jī)外呼系統(tǒng)軟件 百度地圖標(biāo)注點擊事件 杭州智能電話機(jī)器人 內(nèi)蒙古智能電銷機(jī)器人哪家強 濟(jì)源人工智能電話機(jī)器人價格 怎樣在地圖標(biāo)注消火栓圖形 地圖標(biāo)注位置多的錢 山東防封電銷卡辦理套餐

1、httphandler

        

實例1:通過生成一張動態(tài)圖片輸出客戶端的IP地址、操作系統(tǒng)類型、瀏覽器類型

復(fù)制代碼 代碼如下:

%@ WebHandler Language="C#" Class="visitor" %>

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è)置畫布
            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;
        }
    }

}


實例2:通過“下載”連接,彈出用戶附件保存

html代碼:a href="dowload.ashx">下載/a>

復(fù)制代碼 代碼如下:

%@ WebHandler Language="C#" Class="dowload" %>

using System;
using System.Web;

public class dowload : IHttpHandler {

    public void ProcessRequest(HttpContext context)
    {
        string fileName = HttpUtility.UrlEncode("悲劇.jpg");
        context.Response.ContentType = "image/JPEG";

        //打開附件對話框  報文頭header和設(shè)置它的值
        context.Response.AddHeader("Content-Disposition", "attachment:filename=" + fileName);
        context.Response.WriteFile("蘋果.jpg");      
    }

    public bool IsReusable {
        get {
            return false;
        }
    }

}

標(biāo)簽:百色 新鄉(xiāng) 周口 朝陽 臺州 朔州 喀什 洛陽

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《ASP.NET筆記之 Httphandler的操作詳解》,本文關(guān)鍵詞  ASP.NET,筆記,之,Httphandler,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《ASP.NET筆記之 Httphandler的操作詳解》相關(guān)的同類信息!
  • 本頁收集關(guān)于ASP.NET筆記之 Httphandler的操作詳解的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    布拖县| 健康| 西安市| 太白县| 临桂县| 平阴县| 故城县| 漠河县| 弥渡县| 嵊泗县| 阿荣旗| 永平县| 长丰县| 福贡县| 扎赉特旗| 平陆县| 孝昌县| 蒲城县| 繁峙县| 赫章县| 云浮市| 临潭县| 汕头市| 从江县| 汽车| 会理县| 惠州市| 东丽区| 松原市| 鄂尔多斯市| 江门市| 镇安县| 龙川县| 连云港市| 永城市| 吕梁市| 神农架林区| 张家川| 洛南县| 建水县| 衢州市|