views:

54

answers:

1

Hi All,

I am having ASP.NET MVC application in which i am using HTTP handler ashx file to get the image on the page . This image is uploaded by user by scanning the document.

Now my problem is for every user its displaying except one , User is reporting he is not able to see the image even though it was loaded sucessfully , when i checked the logs it shown that server got image. No exception was logged at the server while converting image too :( One more thing this is happening frequently , 70% times user is not able to see the image in the page. 30% time he managed to see the image ... Strange issue Please advice what could be the issue ?

Below is my code

 public class GetImage : IHttpHandler, System.Web.SessionState.IRequiresSessionState
{

    public GetImage()
    {

    }

    public void ProcessRequest(HttpContext context)
    {
        if (context != null)
        {
            if (!string.IsNullOrEmpty(context.Request.Params["side"]))
            {
                bool isFront = false;
                if (context.Request.Params["side"].Equals("Front"))
                {
                    isFront = true;
                }
                else
                {
                    isFront = false;
                }


                ICache Cache = CacheManager.SessionCache;
                DepositState depState = (DepositState)Cache[Constants.DepositSession];

                if (depState != null)
                {
                    byte[] imageByteArray = null;
                    System.IO.MemoryStream imageMemoryStream = null;
                    try
                    {

                        if (isFront)
                        {
                            imageByteArray = System.Convert.FromBase64String(depState.FrontJpegBase64);

                        }
                        else
                        {
                            imageByteArray = System.Convert.FromBase64String(depState.BackJpegBase64);
                        }

                        imageMemoryStream = new System.IO.MemoryStream(imageByteArray);

                        using (System.Drawing.Image img = System.Drawing.Image.FromStream(imageMemoryStream))
                        {
                            img.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
                        }
                    }
                    catch(Exception  ex)
                    {
                        Log.Error(Constants.DefaultErrorCode, "Exception occured while converting image to Base 64 in GetImage.ashx.cs" + ex);

                    }

                    imageMemoryStream.Close();
                    context.Response.Flush();
                }
                else
                {
                    Log.Error(Constants.DefaultErrorCode, " Deposit State object is nullin GetImage.ashx ");

                }



            }
        }
        else
        {
            Log.Error(Constants.DefaultErrorCode, "Context is null in the Process Request  ");
        }


    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}
+2  A: 

I don't see where you are setting the context.Response.ContentType. I haven't tested this, but I wonder if the missing header would cause unpredictable browser behavior.

matt-dot-net