angular cli + windows身份验证后端

Mca*_*nic 8 windows-authentication angular

我创建了一个Angular CLI项目,其中包含对包含web api服务的后端项目的代理引用.

launchSettings.json(后端项目):

...
  "iisSettings": {
    "windowsAuthentication": true,
    "anonymousAuthentication": false,
    "iisExpress": {
      "applicationUrl": "http://localhost:10863/",
      "sslPort": 0
    }
  },
...
Run Code Online (Sandbox Code Playgroud)

proxy.conf.json(前端项目):

{
  "/api": {
    "target": "http://localhost:10863",
    "secure": false,
    "logLevel": "debug"
  }
}
Run Code Online (Sandbox Code Playgroud)

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"
  },
...
Run Code Online (Sandbox Code Playgroud)

然后我启动后端并通过运行启动Kestrel webserver npm start.使用angular2服务,我会对其中一个后端服务进行http-get.由于后端服务在带有Windows身份验证的IISExpress中运行(我想要Windows身份验证),因此出现401错误.

我可以这样做npm run build并浏览我的IISExpress网址并加载由ng build发布的index.html,但我想使用ng服务方法,因为开发更顺畅,因为ng服务在内存中工作.

我的问题是:在开发过程中如何使用Angular CLI和Windows身份验证?

Mca*_*nic 5

对于它的价值,更好的解决方案是使用代理js文件https://github.com/angular/angular-cli/issues/5627#issuecomment-289381319


Mca*_*nic 1

我在这里找到了一个黑客: http://www.meekdeveloper.com/angular-cli-asp-net-core-windows-authentication/ 它有效。我的后端项目现在可以正确识别调用用户User.Identity.Name。这确实是一个 hack,如果 Angular CLI 能够正式支持这个就好了!

  • 死链接 - 很高兴知道您做了什么才能使其正常工作! (3认同)