liveBook · Manning

ASP.NET Core

As explained in ASP.NET Core in Action, 3e

ASP.NET Core is Microsoft's cross-platform, open-source web framework for building web applications and services on .NET.

ASP.NET Core is a cross-platform, open-source web framework for building dynamic applications and services on .NET. It supplies common web infrastructure so you can focus on what your application does rather than writing request handling, login, configuration, and logging facilities from scratch. section 1.1 section 2.1

An application has a useful division of responsibilities: framework code receives requests, handlers such as Razor Pages or Web API controllers deal with web-specific details, and those handlers call your business logic. Business logic can remain ordinary C# code without a direct ASP.NET Core dependency. section 1.1

Choose an application style to fit the job; one application can combine styles.

  • Use Razor Pages for page-based, server-rendered websites, or MVC controllers for server-rendered applications without the page-based approach. section 1.2
  • Use minimal APIs for simple HTTP APIs, Web API controllers when an API needs more structure and features, or gRPC for efficient server-to-server communication. section 1.2
  • Use Blazor WebAssembly for a browser-based application or Blazor Server for a stateful, server-rendered interface that sends updates over WebSockets. section 1.2

When a browser sends an HTTP request, the application's web server—Kestrel by default—turns it into an HttpContext containing request details. The request passes through middleware toward an endpoint that generates a response; the response travels back to the server and browser. The response might be HTML, API data, or an access-denied message, depending on the application. section 1.4.2 section 3.1

Figure 3.1 An overview of an ASP.NET Core application. The ASP.NET Core application receives an incoming HTTP request from the browser. Every request passes to the middleware pipeline, which potentially modifies it and then passes it to the endpoint middleware at the end of the pipeline to generate a response. The response passes back through the middleware to the server and finally out to the browser.
CH03_F01_Lock3

Follow the request through Kestrel, middleware, and the endpoint, then trace the response back to the browser. section 3.1

Start with a small HTTP API

Create a minimal API from a template and call its endpoint to receive “Hello World!”. The local workflow is generate, restore NuGet dependencies, build, and run. Visual Studio 2022 and the .NET CLI offer templates for this and other application styles. section 3.2

ASP.NET Core runs on Windows, Linux, and macOS. Unlike legacy ASP.NET's close relationship with Windows IIS, its applications self-host a web server; a reverse proxy can still sit in front of them. For new .NET web applications it is generally the recommended choice, but moving an existing application calls for assessing its dependencies—especially Windows-specific APIs—and deployment needs. section 1.3 section 2.4.2

As an application grows, shared configuration, dependency injection, and logging support help organize it. The logging interface lets application and framework code write messages through providers and control their verbosity. For deployment, distinguish a local build from a published application: publishing gathers additional files needed to host it. section 1.5 section 26.0 section 27.1.1

How ASP.NET Core in Action, 3e covers it

How deep it goes
Traces requests through Kestrel, HttpContext, middleware, and endpoints, then starts a minimal API; detailed components are developed separately.
Examples
Builds a template-based minimal API returning “Hello World!” and uses a company-information website to illustrate dynamic pages.
What it assumes
Assumes familiarity with C# or a similar object-oriented language; treats HTML and JavaScript familiarity as helpful rather than required.
What you can do after
Build it from scratch with a template, restored dependencies, a compiled application, and a locally callable minimal API.
How it connects
Connects HTTP requests and responses with Kestrel, middleware, Razor Pages, minimal APIs, dependency injection, configuration, and logging.

Also explained in

Compare how 3 books explain ASP.NET Core →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ASP.NET Core in Action, 3e. The section links point to the parts of the book it draws on.