我有一个奇怪的问题。.ashx ASP.NET Handler图像不显示在html中img-element
我创建了一个ASP.NET Handler(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方法检索的图像。
如果我把这个处理程序在浏览器中它显示的图像:
homepagepreisvergleich.de/img/internet/browser.JPG homepagepreisvergleich.de/img/internet/Property.JPG
所以很明显ashx处理程序返回一个图像。
当我尝试在HTML页面中显示图像时,不显示任何内容。
homepagepreisvergleich.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。
有人知道这种奇怪行为的原因是什么以及如何解决它?
问候
亚历山大
嗨ARIC TenEyck, 好吧,我承认:这whas样一个真正愚蠢的错误! 我真的好奇,为什么它不起作用;-) 四只眼睛看到两只以上的眼睛! 感谢您的帮助! :-) Greetings Alexander – Alexander 2009-10-23 23:07:19