主頁(yè) > 知識(shí)庫(kù) > ASP.NET筆記之 Httphandler的操作詳解

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

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

1、httphandler

        

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

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

}


實(shí)例2:通過(guò)“下載”連接,彈出用戶(hù)附件保存

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";

        //打開(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)。
  • 相關(guān)文章
  • 下面列出與本文章《ASP.NET筆記之 Httphandler的操作詳解》相關(guān)的同類(lèi)信息!
  • 本頁(yè)收集關(guān)于ASP.NET筆記之 Httphandler的操作詳解的相關(guān)信息資訊供網(wǎng)民參考!
  • 企业400电话

    智能AI客服机器人
    15000

    在线订购

    合计11份范本:公司章程+合伙协议+出资协议+合作协议+股权转让协议+增资扩股协议+股权激励+股东会决议+董事会决议

    推薦文章