From the course: Building Angular and ASP.NET Web API Apps

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Logging in users

Logging in users

From the course: Building Angular and ASP.NET Web API Apps

Start my 1-month free trial

Logging in users

- [Instructor] Now that we have built the login component we will implement the login mechanism. For that, we are going to first complete the login method in our Web API project, then we are going to see how to call the Web API endpoint from Angular application. And then next we are going to learn how to handle errors in Angular. And finally, will store the response in the localStorage. In the AuthenticationController.cs file, scroll down to the login method. And in here, let us first check if the user model has all the necessary data. So for that, let us write if, then string.IsNullOrEmpty. We check first for the UserName, so user.UserName, or string.IsNullOrEmpty user.Password. So if any of them IsNullOrEmpty, then we want to return a response BadRequest. And as a message, we want to write in here, Enter your username and password. If the user has already provided the username and the password, let us check if this user actually exists in our database. So for that, we first open a…

Contents