我创建了一个 Angular CLI 项目,其中包含对包含 Web API 服务的后端项目的代理引用。
launchSettings.json(后端项目):
...
"iisSettings": {
"windowsAuthentication": true,
"anonymousAuthentication": false,
"iisExpress": {
"applicationUrl": "http://localhost:10863/",
"sslPort": 0
}
},
...
proxy.conf.json(前端项目):
{
"/api": {
"target": "http://localhost:10863",
"secure": false,
"logLevel": "debug"
}
}
package.json(前端项目):
...
"scripts": {
"ng": "ng",
"start": "start http://localhost:4200 && ng serve --proxy-config proxy.conf.json",
"build": "ng build --prod --output-path=..\\CoreTest\\wwwroot",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
...
然后我启动后端并通过运行 npm start
启动 Kestrel 网络服务器。使用 angular2 服务,我对其中一项后端服务执行 http-get 操作。由于后端服务在带有 Windows 身份验证的 IISExpress 中运行
(我想要 windows 身份验证),我收到 401 错误。
我可以执行 npm run build
并浏览到我的 IISExpress url 并加载 ng build 发布的 index.html 但我想使用 ng serve 方法,因为开发更顺利,因为 ng在内存中服务。
我的问题是:如何在开发过程中将 Angular CLI 与 Windows 身份验证结合使用?
最佳答案
就其值(value)而言,更好的解决方案是使用代理 js 文件 https://github.com/angular/angular-cli/issues/5627#issuecomment-289381319
关于angular cli + windows 身份验证后端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42981555/