简体   繁体   English

在https上阻止了Angular templateUrl。 内容必须通过HTTPS提供。”

[英]Angular templateUrl blocked on https “This request has been blocked; the content must be served over HTTPS.”

As the title states, I have an angular directive loading a template within my project "/views/modals/help.html" 如标题所示,我有一个角度指令在项目“ /views/modals/help.html”中加载模板

The templateurl works perfectly on localhost, and on the test servers that use http only. templateurl在localhost上以及仅使用http的测试服务器上均可完美运行。 However, when I get to a server that uses https I get the error: "This request has been blocked; the content must be served over HTTPS." 但是,当我进入使用https的服务器时,收到错误消息:“此请求已被阻止;必须通过HTTPS提供内容。”

I can't find any documentation that talks about how to use templateUrl with https. 我找不到任何有关如何将templateUrl与https一起使用的文档。 Any help is appreciated! 任何帮助表示赞赏!

Ok, so the problem was that Angular was loading a templateUrl while on an HTTPS page. 好的,问题是Angular在HTTPS页面上正在加载templateUrl。 I had expected it to try to load the template via HTTPS since angular, the controller, the directive, etc. were loading via relative URLs on an HTTPS page, which in my mind, means they were loaded with HTTPS. 我曾期望它尝试通过HTTPS加载模板,因为angular,控制器,指令等是通过HTTPS页面上的相对URL加载的,在我看来,这意味着它们已通过HTTPS加载。

For whatever reason, angular did not load the template via HTTPS. 无论出于何种原因,angular都不会通过HTTPS加载模板。 So I changed my directive slightly: 因此,我对指令进行了一些更改:

templateUrl: function() {
    var useHTTPS = window.location.href.indexOf('https') > -1;
    if (useHTTPS) {
        return 'https://www.example.com/path/to/htmlfile.html';
    } else {
        return '/path/to/htmlfile.html';
    }
}

The thing is if you load a https webpage all the resources on the page have to be retrieved using https also. 问题是,如果您加载一个https网页,则该页面上的所有资源也必须使用https来检索。

So if your templates are retrieved from http host to https host they will blocked. 因此,如果您的模板从http主机检索到https主机,它们将被阻止。 The source host would have to implement https. 源主机必须实现https。

ps another thing https://letsencrypt.org/ has started offering free https certification for your servers. ps另一件事https://letsencrypt.org/已开始为您的服务器提供免费的https认证。 Looks like a promising project when they have partnered up with giants like Cisco, Chrome and Mozilla. 当他们与思科,Chrome和Mozilla等巨头合作时,看起来是一个充满希望的项目。

暂无
暂无

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

相关问题 Chrome扩展程序出错-“混合内容:此请求已被阻止; 内容必须通过HTTPS投放” - Error with Chrome extension - “Mixed Content: This request has been blocked; the content must be served over HTTPS” 如何解决此请求已被阻止; 内容必须通过 HTTPS 提供 - how to solve This request has been blocked; the content must be served over HTTPS 混合错误:此请求已被阻止; 内容必须通过 HTTPS 提供 - Mixed Error: This request has been blocked; the content must be served over HTTPS API请求被阻止,内容必须通过HTTPS提供 - API request blocked and the content must be served over HTTPS 混合内容 jQuery ajax HTTPS 请求已在 Laravel 上被阻止 - Mixed content jQuery ajax HTTPS request has been blocked on Laravel 已阻止通过安全连接将地理位置混合访问到https:// localhost:3000,无法访问地理位置 - blocked Access to geolocation was blocked over secure connection with mixed content to https://localhost:3000 未阻止从 HTTPS 页面到 HTTP(非 HTTPS)本地主机地址的混合内容请求 - Mixed-content request from HTTPS page to HTTP (non-HTTPS) localhost address not blocked Codeigniter - jquery.min.js:4 混合内容:内容必须通过 HTTPS 提供 - Codeigniter - jquery.min.js:4 Mixed Content: the content must be served over HTTPS CORS 策略已阻止从来源“null”访问“https://localhost:44395” - Access to fetch at 'https://localhost:44395' from origin 'null' has been blocked by CORS policy XMLHttpRequest已被CORS策略阻止-https://openid-connect-eu.onelogin.com/oidc/token - XMLHttpRequest has been blocked by CORS policy - https://openid-connect-eu.onelogin.com/oidc/token
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM