X-Content-Type-Options = nosniff 解决方法
X-Content-Type-Options = nosniff workaround
我在我的 web.config 中添加了 X-Content-Type-Options header,它的本质是不加载脚本,因为 response.contentType
是“text/html
".
现在,我将响应明确修改为:
Response.Clear();
Response.ContentType = "text/javascript";
调试器甚至命中了这些代码行,但最终 ContentType
是“text/html
”。
如何修改 ContentType
?
P.S。我在 IIS 6 上托管此网站。
您可能需要添加 Response.Flush()
:
Response.Clear();
Response.ContentType = "text/javascript";
Response.Flush();
编辑:
当您使用 MVC 时,您应该在视图中设置内容类型,而不是控制器,如下所示:
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" ContentType="text/javascript" %>
或剃刀:
@{ Response.ContentType = "text/javascript"; }
我在我的 web.config 中添加了 X-Content-Type-Options header,它的本质是不加载脚本,因为 response.contentType
是“text/html
".
现在,我将响应明确修改为:
Response.Clear();
Response.ContentType = "text/javascript";
调试器甚至命中了这些代码行,但最终 ContentType
是“text/html
”。
如何修改 ContentType
?
P.S。我在 IIS 6 上托管此网站。
您可能需要添加 Response.Flush()
:
Response.Clear();
Response.ContentType = "text/javascript";
Response.Flush();
编辑: 当您使用 MVC 时,您应该在视图中设置内容类型,而不是控制器,如下所示:
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" ContentType="text/javascript" %>
或剃刀:
@{ Response.ContentType = "text/javascript"; }