【问题标题】:iis 7 https connection to page blocks any javascript and JQUERYiis 7 https 连接到页面会阻止任何 javascript 和 JQUERY
【发布时间】:2013-06-13 07:46:19
【问题描述】:

我有一个由 IIS 7 托管的 asp.net C# 应用程序。我已安装有效的 SSL 证书并使用 Security Switch 将每个页面从 HTTP 协议传输到 HTTPS。

在我的一个页面上,我使用 JQUERY。具体来说,我有一个使用 Javascript 绘制一些东西的画布,还有一个使用 tablesorter jquery plugin 的 GridView。

当我使用 https 连接时,两者都不起作用,这意味着画布是空的,并且不显示网格视图。

如果我使用普通的 HTTP 协议,一切正常。此外,如果我不使用 gridview 上的 tablesorter 插件,即使使用 https 也可以看到它。

我怀疑 https 连接阻止了我的 javascript,尽管在使用 google chrome 并查看证书时(通过单击地址栏上的小锁)它显示“启用了 java 脚本”。

我的 JQUERY 本身在我网站的 MASTER PAGE 上被引用,而其他脚本(在画布上绘图和表格排序器)被导入到页眉部分的页面上,例如:

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
     <script type="text/javascript" src="/Scripts/jquery.tablesorter.js"></script>
</asp:Content>

查看 chromes 控制台,我看到以下内容(仅在使用 https 连接时):

    [blocked] The page at **** ran insecure content from http://fonts.googleapis.com/css?family=Archivo+Narrow.
 
Resource interpreted as Script but transferred with MIME type text/html: "https://****/Scripts/jquery.tablesorter.js". 
Resource interpreted as Script but transferred with MIME type text/html: "https://****/Scripts/AquaGauge.js".
Resource interpreted as Script but transferred with MIME type text/html: "https://*****/Scripts/jquery-1.10.1.min.js". 
Uncaught SyntaxError: Unexpected token < Scripts/jquery-1.10.1.min.js:1
[blocked] The page at https://***** ran insecure content from http://fonts.googleapis.com/css?family=Archivo+Narrow.

Uncaught ReferenceError: $ is not defined 

如何在使用 HTTPS 连接时也制作我的 javascript 代码?

【问题讨论】:

  • jquery.tablesorter.js 文件是否使用 https 加载?您可以在控制台中查看错误。看看你得到了什么错误
  • 资源解释为脚本,但使用 MIME 类型 text/html 传输:“https://******/Scripts/jquery.tablesorter.js”。未捕获的 ReferenceError: $ 未定义
  • 这似乎暗示 jquery lib 尚未加载
  • 我知道它没有加载。这就是我所说的,使用 https 连接会阻止我的 JQUERY 和 javascripts 引用。
  • Https 不应阻止任何 .js 文件被加载/下载到客户端计算机。您是否在其他浏览器(例如 IE)中尝试过相同的操作?

标签: c# asp.net ssl iis-7 https


【解决方案1】:

我修好了。正在加载的 javascript 抛出了一个完整路径 (https://yoursite.com/Script/jquery.js),尽管它是本地的,而不是通过 file:// 或其他任何方式。

必须添加安全开关以及这些文件的链接。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多