In my current project, I am working with Angular 6 and .Net Core 2.1. The Angular 6 code is in one project, while the .Net Core 2.1 controller methods for login authentication are in another project. I have noticed that both projects are using different localhost port numbers. While I can successfully receive results when making API calls from Postman, I am facing an issue when trying to post data from the Angular service to the controller method.
Specifically, I need to post login credentials to the ValuesController method. However, every time I try to do so, I encounter an HttpErrorResponse.
Scenario 1:
When both the Angular 6 code and the controller (SampledataController) method are in the same project, I can successfully post the request and get a response.
Scenario 2:
The issue arises when the Angular 6 code is in one project and the .Net Core 2.1 controller methods for login authentication are in another project. This communication flow is from (WebProject) LoginService ----> (Api) ValuesController.
https://i.sstatic.net/USYQf.png
LoginService.ts
AuthenticateUser(txtUsername: string, txtPassword: string) {
this.userRoles.UserName = txtUsername;
this.userRoles.Password = txtPassword;
let parameters = new HttpParams().set('txtUsername', txtUsername)
.set('txtPassword', txtPassword);
let headers = new HttpHeaders();
headers.append('Content-Type', 'multipart/form-data');
headers.append('Accept', 'application/json');
const httpOptions = { headers: headers };
return this._httpClient.post(this.base_url + "SampleData/AuthenticateUser/" + txtUsername + "/" + txtPassword , httpOptions);
}
ValuesController.cs
[Route("[controller]")]
public class ValuesController : ControllerBase
{
[Route("[action]/{UserName}/{Password}")]
public ActionResult<IEnumerable<string>> AuthenticateUser(string UserName, string Password)
{
return new string[] { UserName, Password };
}
Below is my solution structure
Solution
--> Angular project
Components
--login component
Services
--Login service
Controller
--SampleDataController
--> WebApi Project
--Controller
-- ValuesController
Please assist me in resolving this issue as I am new to this. Thank you in advance!