1

I am dynamically creating images and need to show those images to users. For that i have created a ashx file but the problem is this ashx file is never getting called not sure why path issue or need add any tags in web.config .. while debugging its not going .. might be its not finding please advise.

EDIT: When i directly hit the ashx url its going and showing some results

EDIT 1: Got to know that session is null in the context any reason ?

or MVC asp.net don't require ashx handlers please advise.

/// <summary>
/// Summary description for $codebehindclassname$
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class GetImage : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {
        Log.Info(" In theGetImage");
        context.Response.Clear();
        byte[] imageByteArray = System.Convert.FromBase64String(context.Session["FrontJpegBase64"].ToString().Replace(' ', '+'));
        // System.IO.MemoryStream imageMemoryStream = new System.IO.MemoryStream(imageByteArray);

        try
        {
            using (System.Drawing.Image img = System.Drawing.Image.FromStream(new System.IO.MemoryStream(imageByteArray)))
            {
                img.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
            }

        }
        catch (System.Exception ex)
        {
                       }
        finally
        {
            // img.Close();
            context.Response.Flush();
        }
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}
0

1 Answer 1

0

in the controller, you need to create a function that return a FileResult

in vb.net

Function img() As FileResult
    Dim bmp As Bitmap = Nothing
    Dim dll As New Chess.cChessBoard

    dll.drawBoardPNG(bmp)

    Dim imgStream As New IO.MemoryStream
    bmp.Save(imgStream, ImageFormat.Png)
    imgStream.Position = 0

    Return File(imgStream.ToArray, "image/png")
End Function

in the view, you only need to call

 <img src="/test/chess/img" />
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.