I created an Angular CLI project with a proxy reference to my backend project that contains the web api services.
launchSettings.json (backend project):
...
"iisSettings": {
"windowsAuthentication": true,
"anonymousAuthentication": false,
"iisExpress": {
"applicationUrl": "http://localhost:10863/",
"sslPort": 0
}
},
...
proxy.conf.json (frontend project):
{
"/api": {
"target": "http://localhost:10863",
"secure": false,
"logLevel": "debug"
}
}
package.json (frontend project):
...
"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"
},
...
Then I fire up the back-end and launch the Kestrel webserver by running npm start
. With an angular2 service I do a http-get to one of the back-end services. Since back-end services run in IISExpress with Windows Authentication
(I want windows authentication), I get a 401 error.
I could do npm run build
and browse to my IISExpress url and load the index.html as published by ng build but I would like to use the ng serve method since development is much smoother because ng serve works in-memory.
My question is: how can I use Angular CLI with Windows Authentication during development?
Go to the properties window of the API project, in the Debug tab, enable SSL, Anonymous Authentication, and Windows Authentication. You can set the App URL as https.
Select 'Authentication' and in this window Enable Windows Authentication and Anonymous Authentication. And that is it. We now have a WebApi secured by Windows Authentication.
a) To create a web api project in windows authentication mode, follow below steps: After choosing ASP.Net Web Application, select Web API template and from the right side click Change Authentication button and select Windows Authentication.
For what it's worth, a better solution is to use a proxy js file https://github.com/angular/angular-cli/issues/5627#issuecomment-289381319
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With