Writing an image to ResponseBase.OutputStream does not work anymore with ASP.NET MVC2 RC2

Posted by labilbe on Stack Overflow See other posts from Stack Overflow or by labilbe
Published on 2010-05-28T06:52:39Z Indexed on 2010/05/28 7:12 UTC
Read the original article Hit count: 299

Filed under:
|
|

The following code worked nice on ASP.NET MVC1

public class ImageResult : ActionResult
{
    public Image Image { get; set; }

    public override void ExecuteResult(ControllerContext context)
    {
        if (Image == null)
        {
            return;
        }
        HttpResponseBase response = context.HttpContext.Response;
        response.ContentType = "image/png";
        Image.Save(response.OutputStream, ImageFormat.Png);
    }
}

I spent some time searching answers but I didn't find anyone.

The error thrown is

OutputStream is not available when a custom TextWriter is used.

© Stack Overflow or respective owner

Related posts about c#

Related posts about asp.net-mvc-2