1

奇妙な問題があります。

ビットマップを取得して返す 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 とまったく同じです。

この奇妙な動作の理由と解決方法を誰かが知っていますか?

ご挨拶

アレクサンダー

4

2 に答える 2

3

HTML に「img src」ではなく「img scr」がありますか?

于 2009-10-23T22:50:07.857 に答える
0

これを行うには、名前空間を追加します。

System.Web.SessionState;

次のように使用します。

public class Handler : IHttpHandler, IRequiresSessionState
于 2012-04-17T06:10:34.160 に答える