Post

Aspnetcore repo calling sequence

When I started sorting out the ASP repo more deeply two years ago, many things weren’t obvious at all. I spent a long time browsing through the classes and groups of classes, but I often got confused and didn’t understand what worked. So, I decided to add my own logger to the repo, which will log the class path, method and line number, and track the call sequence. I can’t say it’s a panacea. But for me, it’s one of the most important components, besides studying the unit tests and examples included in the repository. You can always create your own log and add it anywhere. I log in markdown file because the file path is hidden if you specify it as a link. Take note that this log file hold also emoji. This is an example log, just to show how it looks like, starting from D:\src\aspnetcore\src\Security\samples\Cookies\Program.cs I’m also attaching the log itself.

Start:01.02.2025 9:00:35

  1. 35:6006 main – Program.cs Main:21
  2. 35:6045 Create WebHostBuilder – WebHost.cs CreateDefaultBuilder:156
  3. 35:6057 Adding in config variable started with ASPNETCORE_ and ASPNETCORE_ is cutoff. – WebHostBuilder.cs .ctor:40
  4. 35:612 Add in configurator pair environment= value Hosting:Environment or ASPNET_ENV enviroment variables – WebHostBuilder.cs .ctor:45
  5. 35:6129 Add in configurator pair urls= variable ASPNETCORE_SERVER.URLS enviroment variables – WebHostBuilder.cs .ctor:53
  6. 35:6129 Initiated WebHostBuilderContext by config – WebHostBuilder.cs .ctor:60
  7. 35:6131 Add D:\src\aspnetcore\src\Security\samples\Cookies to configurator with key contentRootWebHost.cs CreateDefaultBuilder:158
  8. 35:6137 Add commands line args if they exist` – WebHost.cs CreateDefaultBuilder:162
  9. 35:6223 – Call UseKestrel, AddRouting, UseIIS, UseIISIntegration – – WebHost.cs ConfigureWebDefaults:229
  10. 35:6225 Specify Kestrel as the server to be used by the web host. – WebHostBuilderKestrelExtensions.cs UseKestrel:150
  11. 35:6353 Configures the port and base path the server should listen on when running behind AspNetCoreModule. – WebHostBuilderIISExtensions.cs UseIIS:24
  12. 35:6353 IsAspNetCoreModuleLoaded hasn’t loaded yet – WebHostBuilderIISExtensions.cs UseIIS:26
  13. 35:6363 –Configures the port and base path the server should listen on when running behind AspNetCoreModule– – WebHostBuilderIISExtensions.cs UseIISIntegration:32
  14. 35:6371 Add to config applicationName WebHostDefaults.ApplicationKey – WebHostBuilderExtensions.cs UseStartup:145
  15. 35:6387 – Call build– – WebHostBuilder.cs Build:139
  16. 35:6443 Loaded from _options.GetFinalHostingStartupAssemblies assembly Cookies – WebHostBuilder.cs BuildCommonServices:235
  17. 35:646 Define contentRootPath D:\src\aspnetcore\src\Security\samples\Cookies – WebHostBuilder.cs BuildCommonServices:266
  18. 35:6481 Created ServiceCollection and added singleton WebHostOptions, WebHostBuilderContext, IWebHostEnvironment, IHostEnvironment – WebHostBuilder.cs BuildCommonServices:270
  19. 35:6489 Add ConfigurationBuilder – WebHostBuilder.cs BuildCommonServices:280
  20. 35:6495 Created ConfigurationBuilder and added Iconfiguration inside it, wrapped in ChainedConfigurationSource – WebHostBuilder.cs BuildCommonServices:284
  21. 35:6504 Add appsettings.json and appsettings.Development.json – WebHost.cs CreateDefaultBuilder:171
  22. 35:6518 Add UserSecrets json file if the assembly has UserSecretsIdAttribute and only in debug mode – WebHost.cs CreateDefaultBuilder:174
  23. 35:6525 Add all variables without filtering by prefix – WebHost.cs CreateDefaultBuilder:187
  24. 35:6526 Add commands line args if they exist – WebHost.cs CreateDefaultBuilder:189
  25. 35:6529 Configure the IWebHostEnvironment to use static web assets. – StaticWebAssetsLoader.cs UseStaticWebAssets:25
  26. 35:6531 Open from bin/Debug with such name Cookies.staticwebassets.runtime.json, it needs for apealing to wwwroot folder – StaticWebAssetsLoader.cs ResolveManifest:47
  27. 35:712 Initiated WebHostBuilderContext.Configuration – WebHostBuilder.cs BuildCommonServices:292
  28. 35:7182 Call _configureServices delegate – WebHostBuilder.cs BuildCommonServices:314
  29. 35:7205 – Add services for logging – – WebHost.cs CreateDefaultBuilder:203
  30. 35:7216 Add config section LoggingWebHost.cs CreateDefaultBuilder:204
  31. 35:7224 Add console services – WebHost.cs CreateDefaultBuilder:205
  32. 35:7225 Add Debug services – WebHost.cs CreateDefaultBuilder:206
  33. 35:7232 Add AddEventSourceLogger services – WebHost.cs CreateDefaultBuilder:207
  34. 35:7236 Change serviceProvider option ValidateScopes – WebHost.cs CreateDefaultBuilder:212
  35. 35:7307 Adds services required for routing requests. – RoutingServiceCollectionExtensions.cs AddRouting:29
  36. 35:7337 Add dependency IStartup – WebHostBuilderExtensions.cs UseStartup:150
  37. 35:7338 Clone hostingServices в applicationServices :bulb:WebHostBuilder.cs Build:141
  38. 35:753 Replacement of some services in applicationServices – WebHostBuilder.cs Build:164
  39. 35:7583 Created WebHost instance – WebHostBuilder.cs Build:166
  40. 35:7739 Call of ConfigureServices from startup which returns IServiceProvider – WebHost.cs EnsureApplicationServices:178
  41. 35:7791 ConfigureServices was called – Startup.cs ConfigureServices:33
  42. 35:7907 Adds services required for routing requests. – RoutingServiceCollectionExtensions.cs AddRouting:29
  43. 35:7955 Add dependency for services AuthenticationService, AuthenticationHandlerProvider, AuthenticationSchemeProvider – AuthenticationCoreServiceCollectionExtensions.cs AddAuthenticationCore:22
  44. 35:8175 Adds services required for routing requests. – RoutingServiceCollectionExtensions.cs AddRouting:29
  45. 35:8179 Add dependency for service AuthenticationService, AuthenticationHandlerProvider, AuthenticationSchemeProvider – AuthenticationCoreServiceCollectionExtensions.cs AddAuthenticationCore:22
  46. 35:8212 Registration service for Authentication – AuthenticationServiceCollectionExtensions.cs AddAuthentication:22
  47. 35:8212 Add dependency for service AuthenticationService, AuthenticationHandlerProvider, AuthenticationSchemeProvider – AuthenticationCoreServiceCollectionExtensions.cs AddAuthenticationCore:22
  48. 35:8215 Initiation AuthenticationBuilder – AuthenticationBuilder.cs .ctor:22
  49. 35:8215 Add first Action to service collection -- [AuthenticationServiceCollectionExtensions.cs](D:\src\aspnetcore\src\Security\Authentication\Core\src\AuthenticationServiceCollectionExtensions.cs) AddAuthentication:62
  50. 35:8223 Add PostConfigureCookieAuthenticationOptions for CookieAuthenticationOptions – CookieExtensions.cs AddCookie:79
  51. 35:8225 Add to service validation action o.Cookie.Expiration == null – CookieExtensions.cs AddCookie:96
  52. 35:8231 in AuthenticationBuilder were added options and scheme CookieAuthenticationOptions, CookieAuthenticationHandle – CookieExtensions.cs AddCookie:103
  53. 35:8775 Run host and listening – WebHostExtensions.cs RunAsync:114
  54. 35:8788 Call HostingEventSource – WebHost.cs StartAsync:128
  55. 35:9027 Call Configure from startup – WebHost.cs BuildApplication:224
  56. 35:9072 Configure was called – Startup.cs Configure:57
  57. 35:9085 Add EndpointRoutingMiddleware – EndpointRoutingApplicationBuilderExtensions.cs UseRouting:61
  58. 35:9088 Add flag Properties[AuthenticationMiddlewareSetKey] true – AuthAppBuilderExtensions.cs UseAuthentication:23
  59. 35:9088 Add AuthenticationMiddleware – AuthAppBuilderExtensions.cs UseAuthentication:25
  60. 36:1608 ApplicationBuilder pipline contains 8 middlewares :exclamation:ApplicationBuilder.cs Build:195
  61. 36:1612 Microsoft.AspNetCore.Builder.UseMiddlewareExtensions+ReflectionMiddlewareBinder.CreateMiddleware;Microsoft.AspNetCore.Builder.UseMiddlewareExtensions+ReflectionMiddlewareBinder.CreateMiddleware;Microsoft.AspNetCore.Builder.UseMiddlewareExtensions+ReflectionMiddlewareBinder.CreateMiddleware;Microsoft.AspNetCore.Builder.UseMiddlewareExtensions+ReflectionMiddlewareBinder.CreateMiddleware;AuthSamples.Cookies.Startup+<>c.b__6_0;Microsoft.AspNetCore.Builder.UseMiddlewareExtensions+ReflectionMiddlewareBinder.CreateMiddleware;Microsoft.AspNetCore.Builder.UseMiddlewareExtensions+ReflectionMiddlewareBinder.CreateMiddleware;Microsoft.AspNetCore.Builder.UseMiddlewareExtensions+ReflectionMiddlewareBinder.CreateMiddleware -- [ApplicationBuilder.cs](D:\src\aspnetcore\src\Http\Http\src\Builder\ApplicationBuilder.cs) Build:197
  62. 36:1888 Set default scheme: YourSchemeName – AuthenticationServiceCollectionExtensions.cs AddAuthentication:45
  63. 36:1905 Add in ctor AuthenticationSchemeProvider authentification scheme YourSchemeName – AuthenticationSchemeProvider.cs .ctor:43
  64. 36:2532 Call ctor HostingApplication, Call _application с context will cause the chain to be called middleware – HostingApplication.cs .ctor:29
  65. 36:4535 Expect CancellationToken.cancel – WebHostExtensions.cs RunAsync:140
  66. 36:4555 Registration of callback by call Cancellation.Cancel – WebHostExtensions.cs WaitForTokenShutdownAsync:159
  67. 36:8641 Received request header name sec-ch-ua, value “Google Chrome”;v=”131”, “Chromium”;v=”131”, “Not_A Brand”;v=”24” :bulb:HttpProtocol.cs OnHeader:531
  68. 36:8717 Received request header name sec-ch-ua-mobile, value ?0 :bulb:HttpProtocol.cs OnHeader:531
  69. 36:8719 Received request header name sec-ch-ua-platform, value “Windows” :bulb:HttpProtocol.cs OnHeader:531
  70. 36:8719 Received request header name upgrade-insecure-requests, value 1 :bulb:HttpProtocol.cs OnHeader:531
  71. 36:872 Received request header name sec-fetch-site, value none :bulb:HttpProtocol.cs OnHeader:531
  72. 36:8725 Received request header name sec-fetch-mode, value navigate :bulb:HttpProtocol.cs OnHeader:531
  73. 36:8725 Received request header name sec-fetch-user, value ?1 :bulb:HttpProtocol.cs OnHeader:531
  74. 36:8725 Received request header name sec-fetch-dest, value document :bulb:HttpProtocol.cs OnHeader:531
  75. 36:8734 Received request header name priority, value u=0, i :bulb:HttpProtocol.cs OnHeader:531
  76. 36:8945 The context creation are initiated by HttpProtocol which create many things incluiding IFeatureCollection – HttpProtocol.cs ProcessRequests:669
  77. 36:895 Created HostContext – HostingApplication.cs CreateContext:44
  78. 36:8955 Created instance DefaultHttpContext – DefaultHttpContextFactory.cs Create:47
  79. 36:8959 Call ctor DefaultHttpContext features initiated httpProtocol – DefaultHttpContext.cs .ctor:64
  80. 36:8984 Initiation DefaultHttpContext, iinteresting implementation- Initiation of all classes by single instance IFeatureCollection – DefaultHttpContext.cs Initialize:79
  81. 36:8984 Initiation IFeatureCollection – DefaultHttpContext.cs Initialize:81
  82. 36:8986 Initiation DefaultHttpRequest – DefaultHttpContext.cs Initialize:83
  83. 36:8988 Initiation DefaultHttpResponse – DefaultHttpContext.cs Initialize:85
  84. 36:899 Initiation DefaultConnectionInfo – DefaultHttpContext.cs Initialize:87
  85. 36:899 Initiation DefaultWebSocketManager – DefaultHttpContext.cs Initialize:89
  86. 36:9225 Kestrel executes ProcessRequestAsync – HttpProtocol.cs ProcessRequests:675
  87. 36:9227 Call ProcessRequestAsync с await RequestDelegate.Invoke(context) call execution middleware chain – HostingApplication.cs ProcessRequestAsync:89
  88. 36:9918 Invoke AuthenticationMiddleware, IAuthenticationFeature are added in HttpProtocol.Generated.cs in ExtraFeatureSet – AuthenticationMiddleware.cs Invoke:42
  89. 36:9921 Add IAuthenticationFeature to HttpProtocol.Generated.cs in ExtraFeatureSet with context.Request.Path: / – AuthenticationMiddleware.cs Invoke:43
  90. 36:9992 Call context.AuthenticateAsync with scheme YourSchemeName – AuthenticationMiddleware.cs Invoke:69
  91. 36:9994 Call AuthenticateAsync – AuthenticationHttpContextExtensions.cs AuthenticateAsync:33
  92. 37:001 Find handler by requesting IAuthenticationHandlerProvider – AuthenticationService.cs AuthenticateAsync:71
  93. 37:0019 Get insntance YourSchemeName – AuthenticationHandlerProvider.cs GetHandlerAsync:44
  94. 37:0049 Leads to option processing and validation – AuthenticationHandler.cs InitializeAsync:154
  95. 37:0077 Defined CookieScheme YourSchemeName options – Startup.cs ConfigureServices:43
  96. 37:0095 ConfigureMyCookie.Configure is called – ConfigureMyCookie.cs Configure:17
  97. 37:0103 post configure CookieAuthenticationOptions, add default values – PostConfigureCookieAuthenticationOptions.cs PostConfigure:32
  98. 37:0109 Added it to the options cookie name .AspNetCore.YourSchemeName – PostConfigureCookieAuthenticationOptions.cs PostConfigure:38
  99. 37:0116 Created protector в loop, purpose YourSchemeName – DataProtectionCommonExtensions.cs CreateProtector:44
  100. 37:0117 Created protector in loop purpose v2 – DataProtectionCommonExtensions.cs CreateProtector:44
  101. 37:0137 Call validation CookieAuthenticationOptions o.Cookie.Expiration == null – CookieExtensions.cs AddCookie:100
  102. 37:0143 Call validation – AuthenticationBuilder.cs AddSchemeHelper:48
  103. 37:0194 Call HandleAuthenticateAsync в CookieAuthenticationHandler – CookieAuthenticationHandler.cs HandleAuthenticateAsync:208
  104. 37:0207 to receive string cookie from request – CookieAuthenticationHandler.cs ReadCookieTicket:155
  105. 37:0314 cookie CfDJ8G3zIoMiAQ5BrlWuIAJEd2rnzYihgFCX3v3i-er5mMjj-spYvDkxLVGWsG4pHn6-lLqv9ueX08ueBqb5z-Bgnu0r8CvQM4tKN2Pch4Nyg87kltQ1CktI_ZqgiXb3VUT-2tcU9H9asZqBh12nMD4j_AYVTEX9P49pE7xPPHoDxdiahIT4iir8jZ2MA3j_V3ZVXYBwkXGNuA2Mj5TKse6qGCtj__7Z-4dHFXzUSRa6GkdyiMvop4VPOxRPhHGZvk52-_JebXz9vJT6-7rCftRZWO8CZHXJc0B3r5orVsJzbNYWzx5MbS33WnSDa4XvP9t-aUG-E-1W-BlqwZ-u5WQXuCy2yARgWxNzBhNVGyEkOI is decrypt , deserialize in AuthenticationTicket class – CookieAuthenticationHandler.cs ReadCookieTicket:162
  106. 37:0659 check if the remaining time is less than the time elapsed since the release, then call the update – CookieAuthenticationHandler.cs CheckForRefreshAsync:95
  107. 37:0675 update – CookieAuthenticationHandler.cs CheckForRefreshAsync:111
  108. 37:0684 result AuthenticateAsync is succefull, add principal to cache – AuthenticationService.cs AuthenticateAsync:82
  109. 37:069 Initiation user type ClaimsPrincipal – DefaultHttpContext.cs User:174
  110. 37:7864 Kestrel execute _bodyControl.StopAsync – HttpProtocol.cs ProcessRequests:720
  111. 44:7559 Received request header name sec-ch-ua, value “Google Chrome”;v=”131”, “Chromium”;v=”131”, “Not_A Brand”;v=”24” :bulb:HttpProtocol.cs OnHeader:531
  112. 44:7559 Received request header name sec-ch-ua-mobile, value ?0 :bulb:HttpProtocol.cs OnHeader:531
  113. 44:7559 Received request header name sec-ch-ua-platform, value “Windows” :bulb:HttpProtocol.cs OnHeader:531
  114. 44:7559 Received request header name upgrade-insecure-requests, value 1 :bulb:HttpProtocol.cs OnHeader:531
  115. 44:756 Received request header name sec-fetch-site, value none :bulb:HttpProtocol.cs OnHeader:531
  116. 44:756 Received request header name sec-fetch-mode, value navigate :bulb:HttpProtocol.cs OnHeader:531
  117. 44:756 Received request header name sec-fetch-user, value ?1 :bulb:HttpProtocol.cs OnHeader:531
  118. 44:756 Received request header name sec-fetch-dest, value document :bulb:HttpProtocol.cs OnHeader:531
  119. 44:756 Received request header name priority, value u=0, i :bulb:HttpProtocol.cs OnHeader:531
  120. 44:7561 Initiated of context creation by HttpProtocol, which apply, including IFeatureCollection – HttpProtocol.cs ProcessRequests:669
  121. 44:7562 Create HostContext – HostingApplication.cs CreateContext:44
  122. 44:7562 Created instance DefaultHttpContext – DefaultHttpContextFactory.cs Create:47
  123. 44:7562 Call ctor DefaultHttpContext features, httpProtocol – DefaultHttpContext.cs .ctor:64
  124. 44:7562 Initiation DefaultHttpContext, Initiation of all classes by single instance IFeatureCollection – DefaultHttpContext.cs Initialize:79
  125. 44:7562 Initiation IFeatureCollection – DefaultHttpContext.cs Initialize:81
  126. 44:7562 Initiation DefaultHttpRequest – DefaultHttpContext.cs Initialize:83
  127. 44:7562 Initiation DefaultHttpResponse – DefaultHttpContext.cs Initialize:85
  128. 44:7562 Initiation DefaultConnectionInfo – DefaultHttpContext.cs Initialize:87
  129. 44:7562 Initiation DefaultWebSocketManager – DefaultHttpContext.cs Initialize:89
  130. 44:7563 Kestrel execute ProcessRequestAsync – HttpProtocol.cs ProcessRequests:675
  131. 44:7564 Call ProcessRequestAsync with await RequestDelegate.Invoke(context) calls middleware chain execution – HostingApplication.cs ProcessRequestAsync:89
  132. 44:7611 Invoke AuthenticationMiddleware, addition of IAuthenticationFeature in HttpProtocol.Generated.cs, ExtraFeatureSet – AuthenticationMiddleware.cs Invoke:42
  133. 44:7611 Add IAuthenticationFeature to HttpProtocol.Generated.cs in ExtraFeatureSet with context.Request.Path: /home/MyClaims – AuthenticationMiddleware.cs Invoke:43
  134. 44:7616 Call context.AuthenticateAsync with scheme YourSchemeName – AuthenticationMiddleware.cs Invoke:69
  135. 44:7616 Call AuthenticateAsync – AuthenticationHttpContextExtensions.cs AuthenticateAsync:33
  136. 44:7623 Found handler by receiving IAuthenticationHandlerProvider – AuthenticationService.cs AuthenticateAsync:71
  137. 44:7628 Get insntance YourSchemeName – AuthenticationHandlerProvider.cs GetHandlerAsync:44
  138. 44:7639 Leads to option processing and validation – AuthenticationHandler.cs InitializeAsync:154
  139. 44:7641 Call HandleAuthenticateAsync in CookieAuthenticationHandler – CookieAuthenticationHandler.cs HandleAuthenticateAsync:208
  140. 44:7641 to receive string cookie from request – CookieAuthenticationHandler.cs ReadCookieTicket:155
  141. 44:7643 cookie CfDJ8G3zIoMiAQ5BrlWuIAJEd2rnzYihgFCX3v3i-er5mMjj-spYvDkxLVGWsG4pHn6-lLqv9ueX08ueBqb5z-Bgnu0r8CvQM4tKN2Pch4Nyg87kltQ1CktI_ZqgiXb3VUT-2tcU9H9asZqBh12nMD4j_AYVTEX9P49pE7xPPHoDxdiahIT4iir8jZ2MA3j_V3ZVXYBwkXGNuA2Mj5TKse6qGCtj__7Z-4dHFXzUSRa6GkdyiMvop4VPOxRPhHGZvk52-_JebXz9vJT6-7rCftRZWO8CZHXJc0B3r5orVsJzbNYWzx5MbS33WnSDa4XvP9t-aUG-E-1W-BlqwZ-u5WQXuCy2yARgWxNzBhNVGyEkOI is decrypt , deserialize in AuthenticationTicket class – CookieAuthenticationHandler.cs ReadCookieTicket:162
  142. 44:7645 check if the remaining time is less than the time elapsed since the release, then call the update – CookieAuthenticationHandler.cs CheckForRefreshAsync:95
  143. 44:7645 update – CookieAuthenticationHandler.cs CheckForRefreshAsync:111
  144. 44:7645 result AuthenticateAsync succesefull principal add to cache – AuthenticationService.cs AuthenticateAsync:82
  145. 44:7646 Initiation of user with type of ClaimsPrincipal – DefaultHttpContext.cs User:174
  146. 44:7867 Call AuthenticateAsync – AuthenticationHttpContextExtensions.cs AuthenticateAsync:33
  147. 44:7877 Received scheme – AuthenticationService.cs AuthenticateAsync:64
  148. 44:7878 Find handler by requsting IAuthenticationHandlerProvider – AuthenticationService.cs AuthenticateAsync:71
  149. 44:7878 Result AuthenticateAsync is successful principal added to cache – AuthenticationService.cs AuthenticateAsync:82
  150. 44:794 Kestrel execute _bodyControl.StopAsync – HttpProtocol.cs ProcessRequests:720
  151. 53:3693 Call CancellationTokenSource.Cancel() – WebHostLifetime.cs Shutdown:72
  152. 53:3697 Stop IHostApplicationLifetime – WebHostExtensions.cs WaitForTokenShutdownAsync:162
  153. 53:3702 Expectation done.Set(); – WebHostLifetime.cs Shutdown:81
  154. 53:3703 Host is stopping. – WebHostExtensions.cs WaitForTokenShutdownAsync:176
  155. 53:3715 Host stop is executing :bulb:WebHost.cs StopAsync:282
  156. 53:3722 _applicationLifetime?.StopApplication – WebHost.cs StopAsync:301
  157. 53:3723 Server.StopAsync – WebHost.cs StopAsync:306
  158. 53:4007 _hostedServiceExecutor.StopAsync – WebHost.cs StopAsync:312
  159. 53:4234 lifetime.SetExitedGracefully – WebHostExtensions.cs RunAsync:98
  160. 53:4236 Call done.Set(); – WebHostExtensions.cs RunAsync:103
This post is licensed under CC BY 4.0 by the author.