濮阳杆衣贸易有限公司

主頁 > 知識庫 > 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)民參考!
  • 推薦文章
    安塞县| 洪江市| 酉阳| 尚志市| 新闻| 景东| 靖远县| 扎鲁特旗| 安仁县| 南川市| 隆化县| 陇西县| 佛山市| 顺昌县| 铜川市| 丰都县| 张家川| 塔河县| 嘉义市| 阜新| 东丰县| 钟山县| 开远市| 饶平县| 徐闻县| 建水县| 大姚县| 娄底市| 烟台市| 修水县| 霍邱县| 淮北市| 崇礼县| 贵德县| 乳山市| 香港| 丹东市| 中山市| 赞皇县| 阳新县| 弥勒县|