dotnetConf-2024-AspNetCore-Source
dotnetConf-2024-AspNetCore-Source
Organized by
Gain deeper understanding of ASP.NET
Thien Nguyen
ASP.NET Core components
Application Startup
Exception Handling
Web UI Services Extensions
https://github.com/dotnet/aspnetcore/blob/main/src/DefaultBuilder/src/WebApplicationBuilder.cs
The Anatomy of a Request
The Server Architecture
https://github.com/dotnet/aspnetcore/blob/main/src/Hosting/Server.Abstractions/src/
IServer.cs
https://github.com/dotnet/aspnetcore/blob/main/src/Extensions/Features/src/
Request Dispatching
Thread Pool
Request Work
Item Thread
Work
Request Item
Infinity Work Thread
ThreadPool.UnsafeQueueUserWorkItem Item
Work
Request
loop
Item
Work Thread
Item
Work Thread
Item
https://github.com/dotnet/aspnetcore/blob/main/src/Servers/Kestrel/Core/src/Internal/
ConnectionDispatcher.cs
HttpContext
• HttpContext encapsulates all HTTP-specific
information about an individual HTTP request.
https://github.com/dotnet/aspnetcore/blob/main/src/Http/Http/src/DefaultHttpContext.cs
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/http-context
https://github.com/davidfowl/AspNetCoreDiagnosticScenarios/blob/master/
AspNetCoreGuidance.md
Authentication
https://github.com/dotnet/aspnetcore/tree/main/src/Http/
Authentication.Abstractions/src
https://github.com/dotnet/aspnetcore/tree/main/src/Http/Authentication.Core/src
https://github.com/dotnet/aspnetcore/blob/main/src/Security/Authentication/
Core/src/
Authentication
Support multiple Schemes: Cookies, Bearer, Windows,…
If only one scheme registered, it is automatically used as
DefaultScheme
https://github.com/dotnet/aspnetcore/blob/main/src/Http/Authentication.Abstractions/src/IAuthenticationHandler.cs
https://github.com/dotnet/aspnetcore/blob/main/src/Http/Authentication.Core/src/AuthenticationService.cs
https://github.com/dotnet/aspnetcore/blob/main/src/Security/Authentication/Core/src/
AuthenticationMiddleware.cs
https://github.com/dotnet/aspnetcore/blob/main/src/Http/Authentication.Abstractions/src/
AuthenticationHttpContextExtensions.cs
https://github.com/dotnet/aspnetcore/blob/main/src/Security/Authentication/Cookies/src/
CookieAuthenticationHandler.cs
Authorization
AuthorizeAttribute only a marker attribute, it does not contain behavior,
authentication is handled in AuthorizationMiddleware and AuthorizationFilter
(legacy)
https://github.com/dotnet/aspnetcore/blob/main/src/Security/Authorization/Core/src/AuthorizeAttribute.cs
https://github.com/dotnet/aspnetcore/blob/main/src/Security/Authorization/Policy/src/AuthorizationMiddleware.cs
https://github.com/dotnet/aspnetcore/blob/main/src/Security/Authorization/Core/src/DefaultAuthorizationService.cs
Custom Authorization Policy Provider
https://github.com/thiennn/aspnetcore-samples/tree/main/CustomAuthorizationPolicyProvider
Global Exception Handling
Don’t write your custom ExceptionHandlerMiddleware
https://github.com/dotnet/aspnetcore/blob/main/src/Middleware/Diagnostics/src/
ExceptionHandler/ExceptionHandlerMiddlewareImpl.cs
Source code of demo
https://github.com/thiennn/aspnetcore-samples
Thank you