context.Response.ContentType = "image/jpg"导致的无法显示 XML 页

前端之家收集整理的这篇文章主要介绍了context.Response.ContentType = "image/jpg"导致的无法显示 XML 页前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

使用asp.net处理图像:@H_403_2@

<%@ WebHandler Language="C#" Class="MakeImage" %>@H_403_2@

using System;
using System.Web;
using System.Drawing;
using System.Drawing.Imaging;@H_403_2@

public class MakeImage : IHttpHandler {

public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "image/jpeg";
string imgPath = "Upload\\1.jpg";
using (Image bmp = Image.FromFile(context.Server.MapPath(imgPath)))
{
using (Graphics g = Graphics.FromImage(bmp))
{
g.DrawString("steve",new Font("微软雅黑",16),Brushes.Black,bmp.Width - 60,bmp.Height - 30);
bmp.Save(context.Response.OutputStream,ImageFormat.Jpeg);
}
}
}

public bool IsReusable {
get {
return false;
}
}@H_403_2@

}@H_403_2@

使用IE8出现如下错误:@H_403_2@

无法显示 XML 页。@H_403_2@

使用 样式表无法查看 XML 输入。请更正错误然后单击 刷新按钮,或以后重试。@H_403_2@


文本内容中发现无效字符。处理资源 'http://localhost:7151/WebOne/MakeImage.ashx' 时出错。@H_403_2@

而用firefox和chrome测试却并未报错,纠结了老半天才发现原来是设置了context.Response.ContentType = "image/jpg"的原因,遂将context.Response.ContentType = "image/jpg"语句删除,IE8打开页面显示成功!但是在firefox、chrome里打开却出现了乱码。@H_403_2@

随后在网上找原因,原来是”image/jpep“而不是“image/jpg",改动后各浏览器测试良好@H_403_2@

原文链接:https://www.f2er.com/xml/300314.html

猜你在找的XML相关文章