刚刚在Chrome中运行了我的网站,令人惊讶的是它对我所有的.png图像都出现了这个警告:
Resource interpreted as image but transferred with MIME type application/octet-stream.
有人以前见过这个吗?
敬礼
刚刚在Chrome中运行了我的网站,令人惊讶的是它对我所有的.png图像都出现了这个警告:
Resource interpreted as image but transferred with MIME type application/octet-stream.
有人以前见过这个吗?
敬礼
当我运行一个使用ASP.NET WebForms应用程序时,遇到了这个问题,使用的是ASP.NET Development Server。
我怀疑如果你将IIS Express作为服务器(VS 2010 SP1),也会发生类似的情况。
在本地,我通过编辑项目设置(Web下)并从ASP.NET Development Server更改为我的本地机器上的IIS'解决'了我的问题。我可以看到PNG已经正确定义为图像MIME类型,当我访问本地IIS服务器时,它确实以正确的类型提供文件。
AddType image/png cur
AddType image/svg+xml svg svgz
当然,上述解决方案是完美的。为了避免警告并使控制台更加清晰,我在我的代码中进行了以下更改(仅适用于ASP.NET开发服务器)。我编写了一个额外的处理程序:
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();
}
}
}
}
在web.config文件的system.web节点下添加了Http Handler。
<system.web>
<httpHandlers>
<add path="*.png" verb="*" type="PNGHandler" />
</httpHandlers>
</system.web>