I have troubles with my c# asp .net core Rest Server. I created an AuthenticationController with a test Route which seems to be working with Postman but when I am trying to get the same result in my Angular 6 Application I get an 404 error that the route is not found, although it is the exact same url.
My Asp .net core Controller:
[Authorize]
[ApiController]
[Route("api/[controller]")]
public class AuthenticationController : ControllerBase
{
private readonly IAuthenticationService _service;
public AuthenticationController(IAuthenticationService service)
{
_service = service;
}
[AllowAnonymous]
[HttpPost("[action]")]
public IActionResult Test()
{
return Ok("It worked");
}
}
My Angular Service where the route is called:
import {Injectable} from '@angular/core';
import {HttpClient, HttpErrorResponse,
HttpHeaders}from'@angular/common/http';
const SERVER_URL = 'http://localhost:4000/api/authentication/';
@Injectable({providedIn: 'root'})
export class LoginService {
public token: string;
constructor(private sessionUser: SessionUserService, private http:
HttpClient, private rolesService: RolesService) {}
test() {
return this.http.post(SERVER_URL + 'test', {})
.map((response: any) => {
console.log(response);
return response;
})
.catch(err => {
console.log(err);
return Observable.of(false);
});
}
}
and here are the different results:
Calling the route from my Angular Client:
Calling the route from Postman:
Output of the asp .net core server console:
As you can see in the console logs from the server there is a 404 and a 200 Request finished. The one with 404 is my Application the one with 200 is the one from Postman.
Note:
CORS shouldn't be a problem since I have the google chrome extension.
I also tried to avoid this error with proxy configuration which angular supports.