-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
Real-World Web Development with .NET 10 - Second Edition
By :
To understand ASP.NET Core, it is useful to first see where it came from.
ASP.NET Core is part of a 30-year history of Microsoft technologies used to build websites and services that work with data that have evolved over the decades:
DbConnection, DbCommand, and DbDataReader. ORMs like EF Core use ADO.NET internally. For example, EF Core for SQL Server references the Microsoft.Data.SqlClient package that implements ADO.NET for SQL Server. Even if you don’t use the rest of ADO.NET, its classes, like SqlConnectionBuilder, can be used to dynamically and safely construct connection strings to SQL Server databases..asp. I include this bullet so that you understand where the ASP initialism comes from because it is still used today in modern ASP.NET Core..aspx file extension. Web Forms is not available on modern .NET, and it should be avoided for new web projects, even with .NET Framework, due to limitations on cross-platform compatibility and modern development practices.
Figure 1.2: Evolution of web user interface technologies in .NET
Good practice: Choose ASP.NET Core to develop websites and web services because it includes web-related technologies that are mature, proven, and cross-platform.
Until modern .NET, ASP.NET was built on top of a large assembly in .NET Framework named System.Web.dll, and it was tightly coupled to Microsoft’s Windows-only web server named Internet Information Services (IIS). Over the years, this assembly has accumulated a lot of features, many of which are not suitable for modern cross-platform development.
ASP.NET Core is a major redesign of ASP.NET. It removes the dependency on the System.Web.dll assembly and IIS and is composed of modular lightweight packages, just like the rest of modern .NET. You can develop and run ASP.NET Core applications cross-platform on Windows, macOS, and Linux. Microsoft has even created a cross-platform, super-performant web server named Kestrel. Using IIS as the web server on Windows is still supported by ASP.NET Core if preferred.
Kestrel is mostly open source. However, it depends on some underlying components and infrastructure that are not fully open source. Kestrel’s open-source components include:
Kestrel’s non-open-source components include:
Also, note that a non-open-source alternative to Kestrel is HTTP.sys. This is a Windows-specific HTTP server, and it is closed source. Applications can use HTTP.sys for edge cases requiring Windows authentication or other Windows-specific networking features, but this is outside of Kestrel itself.
Websites are made up of multiple web pages loaded statically from the filesystem or generated dynamically by a server-side technology such as ASP.NET Core. A web browser makes GET requests using Uniform Resource Locators (URLs) that identify each page and can manipulate data stored on the server using POST, PUT, and DELETE requests.
With many websites, the web browser is treated as a presentation layer, with almost all the processing performed on the server side. Some JavaScript might be used on the client side to implement form validation warnings and some presentation features, such as carousels.
ASP.NET Core provides multiple technologies for building the user interface for websites:
So which should you choose?
”Blazor is now our recommended approach for building web UI with ASP.NET Core, but neither MVC nor Razor Pages are now obsolete. Both MVC & Razor Pages are mature, fully supported, and widely used frameworks that we plan to support for the foreseeable future. There is also no requirement or guidance to migrate existing MVC or Razor Pages apps to Blazor. For existing, well-established MVC-based projects, continuing to develop with MVC is a perfectly valid and reasonable approach.” – Dan Roth
You can see Dan Roth’s original comment post at the following link: https://github.com/dotnet/aspnetcore/issues/51834#issuecomment-1913282747. Dan Roth is the Principal Product Manager on the ASP.NET team, so he knows the future of ASP.NET Core better than anyone else: https://devblogs.microsoft.com/dotnet/author/danroth27/.
I agree with the quote by Dan Roth. For me, there are two main choices:
Much of ASP.NET Core is shared across these two choices anyway, so you will only need to learn about those shared components once, as shown in Figure 1.3:

Figure 1.3: Modern or mature controller-based (and shared) ASP.NET Core components
JetBrains did a survey of 26,348 developers from all around the world and asked about web development technologies and ASP.NET Core usage by .NET developers. The results showed that most .NET developers still use mature and proven controller-based technologies like MVC and Web API. The newer technologies, like Blazor, were far behind. A chart from the report is shown in Figure 1.4:

Figure 1.4: The State of Developer Ecosystem 2023 – ASP.NET Core
It is also interesting to see which JavaScript libraries and cloud host providers are used by .NET developers. For example, 18% use React, 15% use Angular, and 9% use Vue, and all have dropped by a few percent since the previous year. I speculate that this is due to a shift to Blazor instead. For cloud hosting, 24% use Azure, and 12% use AWS. This makes sense for .NET developers since Microsoft puts more effort into supporting .NET developers on its cloud platform.
You can read more about the JetBrains report, The State of Developer Ecosystem 2023, and see the results of the ASP.NET Core question at https://www.jetbrains.com/lp/devecosystem-2023/csharp/#csharp_asp_core.
In summary, C# and .NET can be used on both the server side and the client side to build websites, as shown in Figure 1.5:

Figure 1.5: The use of C# and .NET to build websites on both the server and client side
To summarize what’s new in ASP.NET Core for its mature and proven controller-based technologies, let’s end this section with another quote from Dan Roth:
“We’re optimizing how static web assets are handled for all ASP.NET Core apps so that your files are pre-compressed as part of publishing your app. For API developers we’re providing built-in support for OpenAPI document generation.” – Dan Roth
It is useful to summarize the file types used by these technologies because they are similar but different. If you do not understand some subtle but important differences, it can cause much confusion when trying to implement your own projects. Please note the differences in Table 1.1:
|
Technology |
Special filename |
File extension |
Directive |
|
Razor View (MVC) |
|
||
|
Razor Layout |
|
||
|
Razor View Start |
|
|
|
|
Razor View Imports |
|
|
|
|
Razor Component (Blazor) |
|
||
|
Razor Component (Blazor with page routing) |
|
|
|
|
Razor Component Imports (Blazor) |
|
|
|
|
Razor Page |
|
|
Table 1.1: Comparison of file types used in ASP.NET Core
Directives like @page are added to the top of a file’s contents.
If a file does not have a special filename, then it can be named anything. For example, you might create a Razor View named Customer.cshtml, or you might create a Razor Layout named _MobileLayout.cshtml.
The naming convention for shared Razor files, like layouts and partial views, is to prefix with an underscore, _. For example, _ViewStart.cshtml, _Layout.cshtml, or _Product.cshtml (this might be a partial view for rendering a product).
A Razor Layout file like _MyCustomLayout.cshtml is identical to a Razor View. What makes the file a layout is being set as the Layout property of another Razor file, as shown in the following code:
@{
Layout = "_MyCustomLayout"; // File extension is not needed.
}
Warning! Be careful to use the correct file extension and directive at the top of the file, or you will get unexpected behavior.
Most websites have a lot of content, and if developers had to be involved every time some content needed to be changed, that would not scale well. Almost no real-world website built with .NET only uses ASP.NET Core. A professional .NET web developer, therefore, needs to learn about other platforms built on top of ASP.NET Core.
A CMS enables CMS administrators to define content structure and templates to provide consistency and good design while making it easy for a non-technical content owner to manage the actual content. They can create new pages or blocks of content, and update existing content, knowing it will look great for visitors with minimal effort.
There are a multitude of CMSs available for all web platforms, like WordPress for PHP or Django for Python. CMSs that support modern .NET include Optimizely Content Cloud, Umbraco, Piranha, and Orchard Core.
The key benefit of using a CMS is that it provides a friendly content management user interface. Content owners log in to the website and manage the content themselves. The content is then rendered and returned to visitors using ASP.NET Core MVC controllers and views, or via web service endpoints, known as a headless CMS, to provide that content to “heads” implemented as mobile or desktop apps, in-store touchpoints, or clients built with JavaScript frameworks or Blazor.
This book covers the world’s most popular .NET CMS, Umbraco, in Chapter 14, Web Content Management Using Umbraco CMS, and Chapter 15, Customizing and Extending Umbraco CMS. The quantifiable evidence – usage statistics from BuiltWith, GitHub activity, download numbers, community engagement, and search trends – all point to Umbraco as the most popular .NET-based CMS worldwide. You can see a list of almost 100,000 websites built using Umbraco at the following link: https://trends.builtwith.com/websitelist/Umbraco/Historical.
Umbraco is open source and hosted on GitHub. It has over 2.7k forks and 4.4k stars on its main repository, found at the following link: https://github.com/umbraco/Umbraco-CMS.
The active developer community and constant updates indicate its popularity among developers. Umbraco has reported more than six million downloads of its CMS, which is a significant metric compared to competitors in the .NET CMS space.
You can learn more about alternative .NET CMSs in the GitHub repository at https://github.com/markjprice/web-dev-net10/blob/main/docs/book-links.md#other-net-content-management-systems.
Web applications are often built using technologies known as Single-Page Application (SPA) frameworks, such as Blazor, Angular, React, Vue, or a proprietary JavaScript library. They can make requests to a backend web service to get more data when needed and post updated data using common serialization formats such as XML and JSON. The canonical examples are Google web apps like Gmail, Maps, and Docs.
With a web application, the client side uses JavaScript frameworks or Blazor to implement sophisticated user interactions, but most of the important processing and data access still happens on the server side because the web browser has limited access to local system resources.
JavaScript is loosely typed and is not designed for complex projects, so most JavaScript libraries these days use TypeScript, which adds strong typing to JavaScript and is designed with many modern language features for handling complex implementations.
The .NET SDK has project templates for JavaScript and TypeScript-based SPAs, but we will not spend any time learning how to build JavaScript and TypeScript-based SPAs in this book.
If you are interested in building SPAs with an ASP.NET Core backend, Packt has other books that you might be interested in, as shown in the following list:
In this book, you will learn how to build a controller-based web service using ASP.NET Core Web API, and then how to call that web service from an ASP.NET Core MVC website.
There are no formal definitions, but services are sometimes described based on their complexity:
These days, websites and web services are often deployed to cloud providers like Microsoft Azure or Amazon Web Services. Hundreds of different tools are used to perform the deployments, like Azure Pipelines or Octopus Deploy.
Cloud providers and deployment tools are out of the scope for this book because there are too many choices, and I don’t want to force anyone to learn about or pay for cloud hosting that they will never use for their own projects. Instead, this book covers containerization using Docker in Chapter 8, Configuring and Containerizing ASP.NET Core Projects. Once you have containerized an ASP.NET Core project, it is easy to deploy it to any cloud provider using any deployment or production management tool.
We have now reviewed the important technologies used for web development with .NET. Now, let’s make sure that you know how to get the solutions for all the coding tasks in this book if you get stuck.
Change the font size
Change margin width
Change background colour