I am trying to setup an ASP.NET Core app with Angular frontend by following this tutorial. I was already able to successfully create the projects and I am also able to run and debug them flawlessly. The problem is that for some reason I cannot get proxying the backend calls to the ASP.NET Core backend to work. When I try to call an action inside a controller from the angular app, I get a 404 error.
Here is my proxy.conf.js file:
const PROXY_CONFIG = [
{
context: [
"/api/*",
],
target: "https://localhost:7139",
secure: false
}
]
module.exports = PROXY_CONFIG;
This is my TestController
which I created for testing purposes:
[Authorize]
[ApiController]
[Route("api/[controller]")]
public class TestController : ControllerBase
{
private readonly ILogger<TestController> _logger;
public TestController(ILogger<TestController> logger)
{
_logger = logger;
}
[HttpGet("{id}")]
public string Get(int id)
{
return "Test response";
}
}
Here is how I am trying to call it from within the Angular app:
this.http.get<string>(`api/test/1`).subscribe((value) => {
alert(value);
},
(error) => {
alert(`Error: ${error.error}`);
});
This is how the proxy.conf.js
is added in the serve
section of my angular.json
:
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"configurations": {
"production": {
"browserTarget": "angularproject1.Client:build:production"
},
"development": {
"browserTarget": "angularproject1.Client:build:development"
}
},
"defaultConfiguration": "development",
"options": {
"proxyConfig": "src/proxy.conf.js"
}
},
I already checked the port and in the proxy.conf.json
and it does indeed match the port specified in the applicationUrl
entry of the launchSettings.json
file in the ASP.NET Core project. Here is the content of the launchSettings.json
file:
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": true,
"anonymousAuthentication": false,
"iisExpress": {
"applicationUrl": "http://localhost:30959",
"sslPort": 44345
}
},
"profiles": {
"WebApplication1": {
"commandName": "Project",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:7139;http://localhost:5139",
"dotnetRunMessages": true
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
What could be the reason why this is still not working? Could it be related to the fact that I am trying to get this to work with Windows Authentication, or what am I doing wrong here?