.ashx ASP.NET 处理程序图像未显示在 html img-element 中
我有一个奇怪的问题。
我创建了一个 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 方法检索图像。
如果我在浏览器中调用此处理程序,它将显示图像:
homepagepreisvergleich.de/img/internet/browser.JPG homepagepreisvergleich.de/img/internet/Property.JPG
显然 ashx-handler 返回一个图像。
当我尝试在 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 完全相同。
有人知道这种奇怪行为的原因是什么以及如何解决它吗?
问候
亚历山大
I have a strange problem.
I created an ASP.NET Handler (AccidentMap.ashx) that gets a bitmap and returns it.
Here is the handler:
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;
}
}
}
}
It retrieves an image via the GetMap method.
If I call this handler in the browser it displays the image:
homepagepreisvergleich.de/img/internet/browser.JPG
homepagepreisvergleich.de/img/internet/Property.JPG
So obviously the ashx-handler returns an image.
When I try to display the image within an html-page nothing is displayed.
homepagepreisvergleich.de/img/internet/html.JPG
Here is the html for the page:
<html>
<head>
<title>title</title>
</head>
<body>
<img scr="http://localhost:1849/Modules/Insurance%20Company/AccidentMap.ashx?ID=129" />
</body>
</html>
It is exactly the same url used in both scenarios.
Has somebody got an idea what the reason for this strange behavior is and how to solve it?
Greetings
Alexander
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
HTML 中使用“img scr”而不是“img src”?
You have "img scr" instead of "img src" in the HTML?
您可以通过添加名称空间来做到这一点:
使用它如下:
You can do this by adding namespace:
Use it like: