using System.IO; using System.Web; using System.Web.Mvc; namespace Hiway { public class ImageResult : ActionResult { public ImageResult(string sourceFilename, string contentType) { this.SourceFilename = sourceFilename; this.ContentType = contentType; } public ImageResult(byte[] sourceStream, string contentType) { this.ImageBytes = sourceStream; this.ContentType = contentType; } public override void ExecuteResult(ControllerContext context) { HttpResponseBase response = context.HttpContext.Response; response.Clear(); response.Cache.SetCacheability(HttpCacheability.NoCache); response.ContentType = this.ContentType; if (this.ImageBytes != null) { MemoryStream stream = new MemoryStream(this.ImageBytes); stream.WriteTo(response.OutputStream); stream.Dispose(); } else { response.TransmitFile(this.SourceFilename); } } public string ContentType { get; set; } public byte[] ImageBytes { get; set; } public string SourceFilename { get; set; } } }