由于dotnet core的身份验证问题,Angular 8差异加载失败 [英] Angular 8 differential loading failing due to auth issues with dotnet core
问题描述
我最近使用 ng update
从Angular 7更新到了Angular 8.遵循预期的迁移路径,没有问题后,我进行了构建和部署.一切运行良好,直到我开始检查其他浏览器版本,并意识到其中一些正在从服务器获取 401未经授权
来请求js文件.
I recently updated from Angular 7 to Angular 8 using ng update
. After following the expected migration path with no issues I built and deployed. Everything worked great until I started checking other browser versions and realized some were getting 401 unauthorized
from the server in requesting the js files.
问题是,差分加载是这样完成的:
The issue is, the differential loading is done like this:
< script src ="main-es2015.1234.js" type ="module"></script>
似乎有些浏览器有时不想传递< script type ="module" ...
的身份验证信息.令我惊讶的是,有几种方法可以解决此问题:
It seems that some browsers, some of the time, don't want to pass auth info for <script type="module" ...
. It strikes me that there are several ways to work around this:
- 我可以通过在脚本标记中添加
crossorigin ="use-credentials"
来解决此问题,但是我无法在ng build
. - 我可以调整auth设置,以某种方式允许匿名请求通过我的JS文件,但是我没有找到没有很多复杂性的dotnet核心方法.现在,整个应用仅允许Windows身份验证.如果我允许匿名用户,则不必担心以某种方式将控制器保持打开状态.
- I can work around this by adding
crossorigin="use-credentials"
to the script tag but I haven't been able to find how to do that inng build
. - I can tweak the auth settings to somehow allow anonymous requests through to my JS files but I haven't been able to find the dotnet core method of doing this without a lot of complexity. Right now the entire app only allows windows auth. If I allow anonymous I don't want to have to worry somehow that I've left a controller open.
我认为以前的选择是更清洁的解决方案,但我愿意接受其他选择.
I'm thinking the former option is the cleaner solution but I'm open to alternatives.
推荐答案
自从发布接受的答案以来,McAden建议通过添加crossorigin ="use-credentials"的第一种方式来处理此问题的选项已添加到Angular中CLI选项.
Since the posting of the accepted answer the option to handle this in the first way McAden suggests by adding crossorigin="use-credentials" has been added to the Angular CLI options.
在您的angular.json中添加
In your angular.json add
{
...,
"build": {
"builder": ...,
"options": {
...
"crossOrigin": "use-credentials"
}
}
}
这篇关于由于dotnet core的身份验证问题,Angular 8差异加载失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!