简体   繁体   English

C#ASP X-CONTENT-TYPE-OPTIONS-Internet Explorer不显示PNG文件

[英]C# ASP X-CONTENT-TYPE-OPTIONS - Internet Explorer not displaying PNG files

In an attempt to better secure our website application after running OWASP ZAP it has been advised to set the header X-CONTENT-TYPE-OPTIONS to NOSNIFF, which I've done. 为了在运行OWASP ZAP之后更好地保护我们的网站应用程序安全,建议将标头X-CONTENT-TYPE-OPTIONS设置为NOSNIFF,这已完成。

Since doing that though, any locally hosted PNG files are no longer being displayed on Internet Explorer (various versions), and there is image data in the response (the IE Developer tools will show the image associated with the response). 但是,由于这样做,所有本地托管的PNG文件都不再显示在Internet Explorer(各种版本)上,并且响应中包含图像数据(IE Developer工具将显示与响应关联的图像)。

Having checked the responses, I can see that the MIME type being requested is image/png but the response MIME type is octet-stream. 检查响应后,我可以看到请求的MIME类型是image / png,但是响应MIME类型是八位字节流。

Figuring this was a problem with known MIME types, during the APPLICATION_BEGINREQUEST phase I tried checking for PNG requests and setting HttpContext.Current.Response.ContentType = "image/png"; 弄清楚这是已知MIME类型的问题,在APPLICATION_BEGINREQUEST阶段,我尝试检查PNG请求并设置HttpContext.Current.Response.ContentType =“ image / png”; but the response still ended up as an octet-stream. 但是响应仍然以八位字节流的形式结束。

        if (HttpContext.Current.Request.Url.ToString().ToLower().Contains(".png"))
        {
            HttpContext.Current.Response.ContentType = "image/png";
        }

I've also tried modifying the applications web.config to add: 我也尝试修改应用程序web.config以添加:

<system.webServer>
  <staticContent>
     <mimeMap fileExtension=".png" mimeType="image/png" />
  </staticContent>
</system.webServer>

...but that didn't change anything either. ...但是那也没有改变任何东西。

I'm guess there must be a solution to this problem, but so far I've not managed to find one! 我想必须对此问题有解决方案,但到目前为止,我还没有找到解决方案!

Does anyone have the solution to this problem? 有谁能解决这个问题?

Thanks in advance! 提前致谢!

After a quick check on MIME types on an IIS instance, I decided to go ahead and deploy the application without the web.configuration changes, and without the ContentType code. 在快速检查了IIS实例上的MIME类型之后,我决定继续进行部署,而无需更改web.configuration和ContentType代码。

Low and behold, everything is being rendered in IE as it should be. 低估了,一切都应该在IE中呈现。

Therefore whatever the problem is, this appears to be an issue with Cassini! 因此,无论问题出在哪里,这似乎都是卡西尼号的问题!

Hopefully this saves someone from any lengthy investigation in the future! 希望这可以使某人免于以后进行任何冗长的调查!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM