Improving On The Applications Behavior Slides
Improving On The Applications Behavior Slides
Gill Cleeren
CTO XPIRIT BELGIUM
@gillcleeren www.snowball.be
Overview
Handling errors in the API
Adding logging capabilities
Authenticating users
Handling Errors in the API
Handling Exceptions
Using custom
exceptions Middleware in API
Defined in the Core project Converts the exception for use
Derive from by the client
ApplicationException
public class NotFoundException : ApplicationException
{
Request
Response
Writing Custom Middleware
{ ... }
}
Demo
Creating custom exception classes
Throwing exceptions from Core code
Converting exceptions using middleware
Adding Logging Capabilities
Steps to Enable Logging in the Application
Provider-based
LogLevel
private readonly ILogger<CreateEventCommandHandler> _logger;
...
NuGet package
Structured logging
<PackageReference Include="Serilog" Version="2.10.0" />
NuGet Packages
Demo
Adding Serilog
Configuring the logger
Logging from the application code
Authenticating Users
API authentication
- JWT token
- Header of request
- Different options exist
• ASP.NET Identity
• Identity Server
• External provider
Authentication Flow
API
Authentication
Other API
endpoints
Blazor app
[Authorize]
[Route("api/[controller]")]
[ApiController]
{ ... }
Bethany
Team Lead at GloboTicket
“This is great, we can now use this as the
foundation for all future projects.”
Bob T. Hickett
Congratulations
on finishing this course!