用ashx生成图片页面,但无法显示....浏览器提示无法显示 XML 页。 我的代码如下:<%@ WebHandler Language="C#" Class="访问者信息" %>using System;
using System.Web;
public class 访问者信息 : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/JPEG";
        using(System.Drawing.Bitmap bitmap=new System.Drawing.Bitmap(200,200))
        {
            using(System.Drawing.Graphics g=System.Drawing.Graphics.FromImage(bitmap))
            {
                g.DrawString("ip:" + context.Request.UserHostAddress, new System.Drawing.Font("宋体", 20), System.Drawing.Brushes.Red, 0, 0);
                g.DrawString("操作系统" + context.Request.Browser.Platform, new System.Drawing.Font("宋体", 20), System.Drawing.Brushes.Red, 0, 30);
                g.DrawString("浏览器:" + context.Request.Browser.Version, new System.Drawing.Font("宋体", 20), System.Drawing.Brushes.Red, 0, 60);
               
            }
            bitmap.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
        }
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }}
帮忙分析下,感激不尽啊  我初学啊

解决方案 »

  1.   

    浏览器显示以下错误
    无法显示 XML 页。 
    无法查看使用 样式表的 XML 输入。请更正错误然后单击 刷新 按钮,或稍后重试。 
    --------------------------------------------------------------------------------文本内容中发现无效字符。处理资源 'http://localhost:40305/WebSite7/handler/message.ashx' 时出错。 
     
      

  2.   

     context.Response.ContentType = "image/jpeg";
      

  3.   

    我也觉得是ContentType 的问题
      

  4.   

    context.Response.ContentType = "image/jpeg";public class 访问者信息,
    命名规范点
      

  5.   

    呵呵,楼主估计自己写的ContentType吧。
      

  6.   

    context.Response.ContentType = "image/JPEG";还要改下配置文件