MIME type warning in chrome for png images

依然范特西╮ 提交于 2019-12-18 10:09:35

问题


Just ran my site in chrome and suprisingly it comes up with this warning for each of my .png images:

Resource interpreted as image but transferred with MIME type application/octet-stream.

Anyone seen this before?

Regards


回答1:


I encountered this while running an ASP.NET WebForms app using the ASP.NET Development Server.

I suspect something similar will happen if you use IIS Express as your server as well (VS 2010 SP1).

I 'resolved' my problem locally by editing the project settings (under Web) and changed from the ASP.NET Development Server to IIS on my local machine. I can see that PNG was already defined correctly as an image MIME type and indeed when I hit my local IIS server it's serving up the file with the correct type.




回答2:


This warning is telling you that your web server isn't configured to send the correct MIME type meta data for PNG images. You should probably consult the administrator for your web server and ask them to set the correct MIME mapping




回答3:


I added types like this in .htaccess (AddType image/type extention) i.e.

AddType image/png cur
AddType image/svg+xml svg svgz



回答4:


Ofcourse above solutions are perfect. Just to avoid warnings and for a clean console I done following change in my code. (that too only for ASP.NET Development Server) I written a extra handler for this:

PNGHandler.cs

class PNGHandler : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    { 
       if(context.Request.HttpMethod == "GET") 
       {
             string requestedFile = context.Server.MapPath(context.Request.FilePath);
             FileInfo fileinfo = new FileInfo(requestedFile);
             string contentType = "";
             if (fileinfo.Exists && fileinfo.Extension.Remove(0, 1).ToUpper() == "PNG")
             {
                   contentType = "image/png";
                   context.Response.ContentType = contentType;
                   context.Response.TransmitFile(requestedFile);
                   context.Response.End();
              }
         }
    }
}

And added Http Handler in web.config under system.web

<system.web>
 <httpHandlers>
 <add path="*.png" verb="*" type="PNGHandler" />
 </httpHandlers>
</system.web>



回答5:


The quickest way around the spam that I've found is to use the CTRL key to select Errors, Warnings and Debug instead of all.

All:

Errors, Warnings and Debug:




回答6:


I've solved this problem by enabling Static Content in Control Panel > Programs and Features > Turn Windows features on or off > IIS components > World Wide Web Services > Common HTTP Features



来源:https://stackoverflow.com/questions/3235649/mime-type-warning-in-chrome-for-png-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!