我有一个奇怪的问题。
我创建了一个获取位图并返回它的 ASP.NET 处理程序 (AccidentMap.ashx)。
这是处理程序:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Drawing;
namespace BackOffice.Modules.Insurance_Company
{
/// <summary>
/// Summary description for $codebehindclassname$
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class AccidentMap : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
try
{
int id = Convert.ToInt32(context.Request.QueryString["ID"]);
System.Web.Security.MembershipUser user = System.Web.Security.Membership.GetUser(context.User.Identity.Name);
InsuranceCompany.InsuranceCompany insuranceCompany = new InsuranceCompany.InsuranceCompany();
InsuranceCompany.Accident.Map map = insuranceCompany.GetMap(id, user.UserName, user.GetPassword());
Bitmap bitmap = map.Image;
System.IO.MemoryStream stream = new System.IO.MemoryStream();
byte[] bitmapBytes;
bitmap.Save(stream, bitmap.RawFormat);
bitmapBytes = stream.ToArray();
context.Response.ContentType = "image/jpeg";
context.Response.OutputStream.Write(bitmapBytes, 0, bitmapBytes.Length);
}
catch
{
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
它通过 GetMap 方法检索图像。
如果我在浏览器中调用这个处理程序,它会显示图像:
主页preisvergleich.de/img/internet/browser.JPG 主页preisvergleich.de/img/internet/Property.JPG
所以很明显 ashx-handler 返回一个图像。
当我尝试在 html 页面中显示图像时,没有显示任何内容。
主页preisvergleich.de/img/internet/html.JPG
这是页面的html:
<html>
<head>
<title>title</title>
</head>
<body>
<img scr="http://localhost:1849/Modules/Insurance%20Company/AccidentMap.ashx?ID=129" />
</body>
</html>
它与两种场景中使用的 url 完全相同。
有人知道这种奇怪行为的原因是什么以及如何解决它?
问候
亚历山大