简体   繁体   English

为什么 Internet Explorer 调试器在代码和 iis 类型设置为 application/javascript 时将 javascript 文件识别为 text/html?

[英]Why does Internet Explorer debugger identify javascript file as text/html when in the code and in iis the type is set as application/javascript?

When setting X-Content-Type-Options to "nosniff", all the javascript files on my website are blocked due to "mime type mismatch".将 X-Content-Type-Options 设置为“nosniff”时,由于“mime 类型不匹配”,我网站上的所有 javascript 文件都被阻止。

In my code, I have many javascript files which are used in aspx files.在我的代码中,我有许多在 aspx 文件中使用的 javascript 文件。 Here are just a few of the declarations from within the aspx file: (note: there are many more)这里只是 aspx 文件中的一些声明:(注意:还有更多)

<script type="application/javascript" src="../Scripts/OrderEditScripts.js"></script>
<script type="application/javascript" src="../Scripts/ImageControlScripts.js"></script>
<script type="application/javascript" src="../Scripts/ImageEditScripts.js"></script>

Via many google searches, I have been led to also setting the MIME types in IIS.通过许多谷歌搜索,我还被引导在 IIS 中设置 MIME 类型。 I have done so.我已经这样做了。

So, now I have code that is set to: "application/javascript" and IIS Mime type settings that are set to "application/javascript" for.js files.因此,现在我将代码设置为:“application/javascript”和 IIS 设置为“application/javascript” for.js 文件的 Mime 类型设置。

However, these files are still being blocked for mime type mismatch.但是,这些文件仍因 mime 类型不匹配而被阻止。

When using the Internet Explorer debugger, if I click on the "Network" tab, I can see the request made for every file.使用 Internet Explorer 调试器时,如果单击“网络”选项卡,我可以看到对每个文件的请求。

Looking at the javascript files that are requested, I can see that in the column called "Content type", the debugger is showing "text/html"查看请求的 javascript 文件,我可以看到在名为“内容类型”的列中,调试器显示“文本/html”

Also in the debugger, on the right hand pane, in the headers tab, I can see the request headers and the response headers.同样在调试器的右侧窗格中,在标头选项卡中,我可以看到请求标头和响应标头。

The request headers show:请求标头显示:
Accept: application/javascript, / ;q-0.8接受:应用程序/javascript,/;q-0.8

The response headers show: Content-Type: text/html;响应头显示: Content-Type: text/html; charset-utf-8字符集-utf-8

I have a feeling this is where the "mismatch" is happening, but I don't know where the "text/html" is coming from.我有一种感觉,这是发生“不匹配”的地方,但我不知道“text/html”来自哪里。 As mentioned, my code has the type set to "application/javascript" and IIS is set to "application/javascript".如前所述,我的代码类型设置为“application/javascript”,IIS 设置为“application/javascript”。

I will include an image to try and encapsulate everything that is going on:我将包含一个图像来尝试封装正在发生的所有事情:

(apparently I need at least 10 reputation points before I can post an image, so I can't provide any images). (显然我需要至少 10 个声望点才能发布图片,所以我无法提供任何图片)。

The expected result is that I do not get a mime type mismatch and that my javascript files are allowed to execute.预期的结果是我没有得到 mime 类型不匹配,并且我的 javascript 文件被允许执行。

I figured it out.我想到了。

There was a setting in the web.config that was causing this. web.config 中有一个设置导致了这种情况。

I don't know the reason it works, but I commented out that setting.我不知道它起作用的原因,但我注释掉了那个设置。

In the "system.webServer" section, there was a section for "handlers" In the "handlers" section, the following needed to be commented out:在“system.webServer”部分中,有一个“handlers”部分在“handlers”部分中,需要注释掉以下内容:

<add name="JS" path="*.js" verb="GET, HEAD, POST, DEBUG" type="System.Web.UI.PageHandlerFactory" resourceType="Unspecified" requiredAccess="Script" />

After commenting out this section, the javascript files are no longer blocked due to mime type mismatches.注释掉此部分后,javascript 文件不再因 mime 类型不匹配而被阻止。

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

相关问题 如何将VS Code Debugger附加到Internet Explorer 11 for JavaScript / HTML - How to attach VS Code Debugger to Internet Explorer 11 for JavaScript/HTML 我可以在Internet Explorer 11的调试器中修改Javascript代码吗? - Can I modify Javascript code in Internet Explorer 11's debugger? 在Internet Explorer中使用Javascript生成的html代码的问题 - Issue with Javascript generated html code in Internet Explorer 为什么这个Javascript重定向代码无法在Internet Explorer 8中运行? - Why is this Javascript redirect code not working in internet explorer 8? 为什么此Javascript可在Firefox中运行,但不能在Internet Explorer中运行? - Why does this Javascript work in Firefox, but not Internet Explorer? 等效于Internet Explorer,用于在javascript中加载文本文件 - Internet explorer equivalent for loading a text file in javascript Javascript在Internet Explorer 8中不起作用 - Javascript does not work in Internet Explorer 8 为什么此javascript代码在Internet Explorer中不起作用? - Why doesn't this javascript code work in Internet Explorer? 为什么我的JavaScript函数在Internet Explorer中不起作用 - Why does my javascript function not work in Internet explorer 在Internet Explorer中运行本地“Javascript Dependent”HTML文件 - Run local 'Javascript Dependant' HTML file in Internet Explorer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM