国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

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

2024-07-10 12:45:39
字體:
來源:轉載
供稿:網友

1、httphandler

        

實例1:通過生成一張動態圖片輸出客戶端的IP地址、操作系統類型、瀏覽器類型
代碼如下:
<%@ 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))
        {
            //設置畫布
            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));
                //操作系統
                g.DrawString("操作系統:" + 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>
代碼如下:
<%@ WebHandler Language="C#" Class="dowload" %>

using System;
using System.Web;

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 高邮市| 富民县| 精河县| 青神县| 黑龙江省| 长治县| 黄冈市| 大冶市| 荣昌县| 广丰县| 镇坪县| 邯郸市| 镇赉县| 金坛市| 密山市| 义乌市| 虹口区| 平谷区| 五莲县| 江西省| 泸溪县| 义乌市| 三穗县| 辽源市| 阿坝| 南漳县| 玉龙| 图们市| 拉萨市| 广丰县| 富顺县| 安乡县| 息烽县| 托里县| 华亭县| 甘南县| 贵定县| 故城县| 宜春市| 盐山县| 沁阳市|