2009-10-23 67 views
1

我有一個奇怪的問題。.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。

有人知道這種奇怪行爲的原因是什麼以及如何解決它?

問候

亞歷山大

回答

3

你必須在HTML 「IMG SCR」,而不是 「IMG SRC」?

+0

嗨ARIC TenEyck, 好吧,我承認:這whas樣一個真正愚蠢的錯誤! 我真的好奇,爲什麼它不起作用;-) 四隻眼睛看到兩隻以上的眼睛! 感謝您的幫助! :-) Greetings Alexander – Alexander 2009-10-23 23:07:19

0

您可以通過添加命名空間做到這一點:

System.Web.SessionState; 

這樣使用它:

public class Handler : IHttpHandler, IRequiresSessionState