title: ashx served image renders badly in IIS 8
body: <p>I have developed a simple ashx service that pics images from a far-far-away system and renders them in a .net application. Everything works just fine in development that is supposed to be identical to the production environment, hence this seem to be a configuration error.</p>
  
  <p>A page where an image is implemented also returns this message in the log window</p>
  
  <blockquote>
    <p>Resource interpreted as Image but transferred with MIME type text/html</p>
  </blockquote>
  
  <p>In production</p>
  
  <p><img src="https://i.stack.imgur.com/kzim4.jpg" alt="enter image description here"></p>
  
  <p>In development</p>
  
  <p><img src="https://i.stack.imgur.com/4JTlf.jpg" alt="enter image description here"></p>
  
  <p>Also, the code and web.config and similar are identical in the environments. I've even copied the entire dev-tree and run it on the development server with the exact same result.</p>
  
  <p>My implementation looks like this</p>
  
  <pre><code>&lt;system.webServer&gt;
    &lt;validation validateIntegratedModeConfiguration="false" /&gt;
    &lt;handlers accessPolicy="Read, Write, Script, Execute"&gt;
      &lt;remove name="SPImage" /&gt;
      &lt;add name="SPImage" verb="GET" path="SPImage.ashx" type="Web.Business.Handlers.SPImage, Web" /&gt;
    &lt;/handlers&gt;
  &lt;/system.webServer&gt;
  </code></pre>
  
  <p>And the handler</p>
  
  <pre><code>namespace Web.Business.Handlers
  {
      public class SPImage : IHttpHandler
      {
          public bool IsReusable { get { return true; } }
  
          public void ProcessRequest(HttpContext context)
          {
              Guid imageGuid;
              if (!Guid.TryParse(context.Request.QueryString["id"], out imageGuid))
  
              // Get user
              var user = aspnet_MembershipController.Read&lt;aspnet_MembershipListModel&gt;(context.User.Identity.Name);
  
              // Get requested image
              var image = GalleryListController.ReadImage&lt;IGalleryPicture&gt;(user.ID, imageGuid);
              byte[] file = DownloadProcedureController.Download&lt;byte[]&gt;("gallerier", image.Webimage);
  
              int width = 270;
              int height = 180;
  
              // Return image in scaled format
              var stream = new MemoryStream();
              var settings = new ResizeSettings(string.Format("width={0};height={1};format=jpg;quality={2};mode=crop", width, height, 100)) {};
              // ...process the image
              new ImageResizer.ImageJob(file, stream, settings).Build();
  
              HttpResponse httpResponse = context.Response;
              httpResponse.ContentType = "image/jpeg";
              //httpResponse.CacheControl = "no-cache";
              httpResponse.BufferOutput = false; //Stream the content to the client, no need to cache entire streams in memory...
              httpResponse.BinaryWrite(stream.GetBuffer());
              httpResponse.End();
  
          }
      }
  }
  </code></pre>
  
  <p>Any one recognize this?</p>
  
  <p>Thanks</p>