Pergunta

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.

A page where an image is implemented also returns this message in the log window

Resource interpreted as Image but transferred with MIME type text/html

In production

enter image description here

In development

enter image description here

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.

My implementation looks like this

<system.webServer>
  <validation validateIntegratedModeConfiguration="false" />
  <handlers accessPolicy="Read, Write, Script, Execute">
    <remove name="SPImage" />
    <add name="SPImage" verb="GET" path="SPImage.ashx" type="Web.Business.Handlers.SPImage, Web" />
  </handlers>
</system.webServer>

And the handler

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<aspnet_MembershipListModel>(context.User.Identity.Name);

            // Get requested image
            var image = GalleryListController.ReadImage<IGalleryPicture>(user.ID, imageGuid);
            byte[] file = DownloadProcedureController.Download<byte[]>("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();

        }
    }
}

Any one recognize this?

Thanks

Foi útil?

Solução

It was a fault in ImageReziser where the quality wasn't correctly set. Hence the compressed result. Fixed by updating ImageRezising.net

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top