Software

Is this an ASP.NET Core I see before me? Where to next for Microsoft's confusing web framework...

Too many choices?

32 Got Tips?

Microsoft's ASP.NET Core, a web application framework (or more accurately, a family of frameworks), has made strides in performance and innovation, but its rapid development has resulted in a bewildering range of choices facing developers.

The original ASP.NET was launched simultaneously with .NET itself, way back in 2002, co-developed by Microsoft’s Scott Guthrie and Mark Anderson. It was a replacement for the COM-based Active Server Pages. Perhaps the best and worst thing about ASP.NET 1.0 was the form-based programming model that (somewhat) handled state management for you, making it an easier transition for desktop developers, but with downsides in areas like unit testing, responsive user interfaces, and compatibility with modern JavaScript libraries. Now called web forms, this approach is still popular, but limited to the Windows-only .NET Framework.

In early 2009 Microsoft launched ASP.NET MVC, a new framework based on the model-view-controller pattern. It had many advantages over web forms, including better performance, easy integration with JavaScript, amenable unit testing, and a cleaner programming model. Although it was widely adopted in the .NET community, some developers preferred to stick with the mature web forms approach. Further confusing matters, it is possible to combine MVC and web forms, by using MVC routing with web forms pages.

As ASP.NET MVC evolved, Microsoft developed the Razor syntax for View pages. Razor lets you combine C# code and HTML mark-up with minimal ceremony. Razor was initially used for ASP.NET MVC but soon took on a life of its own, with support for projects that use Razor pages but without the MVC pattern.

Then came .NET Core and ASP.NET Core, first fully released in 2016, Microsoft's official cross-platform and open source implementation of .NET. The company implemented ASP.NET Core MVC, but not web forms.

To Blazor with you

In 2018, a new approach called Blazor joined the fray. Blazor began life with the Xamarin (.NET for mobile and Mac) team at Microsoft, who were working on compiling the Mono .NET runtime to WebAssembly. The name is a combination of Browser and Razor. The initial idea was to have a framework for single page applications (SPAs) written in C# and running in the browser. Developers could write C# everywhere, as opposed to mixing C#, JavaScript and perhaps TypeScript. Visual Studio, the primary tool for developing with ASP.NET, is a much better editor for C# than it is for JavaScript.

Blazor was released as part of .NET Core 3.0 in September 2019, by which time it had somewhat changed shape. The initial release is for Blazor server-side applications, which does not use WebAssembly at all. Instead, Razor components run on the server and update the browser user interface via SignalR, Microsoft's framework for real-time communications.

Blazor WebAssembly is in preview. The code the developer writes for Blazor Server or Blazor WebAssembly is pretty much the same, but the outcome is very different. As the documentation notes, with Blazor Server, "Higher latency usually exists. Every user interaction involves a network hop." Blazor Server also has advantages, with smaller download size and no requirement for WebAssembly support, but the WebAssembly option looks more attractive for most scenarios.

There is also ASP.NET Web API, a framework for building REST APIs with models and controllers adapted from ASP.NET MVC, which is suitable for serving data to mobile as well as web applications.

Microsoft presents some of the choices for ASP.NET Core

Strong features of ASP.NET Core are that it is cross-platform, well suited to container deployment, and easily tested. Another key feature is dependency injection, where classes do not directly create instances of the service objects on which they depend, but have them passed to them, usually in the constructor. This achieves loose coupling, a good principle but one which can be confusing for beginners. Tooling for ASP.NET Core is flexible, a far cry from the days when developing outside Visual Studio was painful. Today you can also use Visual Studio for the Mac, the cross-platform Visual Studio Code, or any text editor.

Microsoft's web platform is not as confusing as its desktop platform, but does present developers with a confusing array of choices. One of them, ASP.NET MVC, is not quite deprecated but heading in that direction. Microsoft's documentation now says that: "For new development, we recommend Razor Pages over MVC with controllers and views."

In fact, the documentation authors cannot keep up with all the permutations. The page referenced above, a tutorial for data access with ASP.NET MVC, states that "There is a Razor Pages version of this tutorial. Each tutorial covers some material the other doesn't."

Architecture choices

The company offers a free book [PDF] on architecting ASP.NET Core applications which offers some clues about how Microsoft sees these choices. Web Forms, it says, "continues to be a robust and reliable platform." Blazor "provides a rich client experience," and is ideal where "your team is more comfortable with .NET development than JavaScript or TypeScript."

Traditional web applications (like ASP.NET MVC or Razor Pages) are aimed at simple applications or where teams are unfamiliar with JavaScript or TypeScript. SPAs are for rich experiences but "require greater architectural and security expertise," said the author Steve Smith. The book is a good read for newcomers trying to make sense of the platform overall, with explainers on all the essential pieces, including commonly used JavaScript frameworks like jQuery, Angular, React.js and Vue.js.

Architecting an ASP.NET application: a handy book for navigating the key concepts

Steve Gordon, a senior .NET developer at Brighton-based Madgex, which develops recruitment software, is also a .NET trainer and has been using ASP.NET since its first introduction. He now uses ASP.NET Core and says "it's a very efficient product to work with, we can build out microservices very quickly and very easily with it."

He says the platform is not so confusing if you have followed it through the various changes. What does he think of Blazor? "I can see that it might be an easier onboarding experience for someone experienced in building single-page apps with Node.js to make a transition, as well as to help .NET developers that are more familiar with C# to continue coding and working in the browser," he told The Register.

One of the issues with ASP.NET Core is that new releases bring breaking changes. Gordon says that part of the solution for enterprise developers is to note Microsoft's different support models for long term support (LTS) releases. For example, .NET 3.0 is not an LTS release, but .NET 3.1 is. The policy is laid out here. "I've seen developers fall into the trap that they adopt the latest current release not realising that the support will run out soon, where Microsoft has historically supported things much longer."

Microsoft does tend to tangle ASP.NET Core with another of its frameworks, the database object-relational mapping technology called Entity Framework EF Core. At its best, it is like magic: developers simply write C# classes to represent data, and EF generates the tables and lets developers work with C# objects rather than having to think about the database. There are a number of snags, though. If you take a naïve approach to using EF Core, performance often becomes a problem, and the simplicity tends to dissolve where relationships are complex. It may not work well if you use databases other than Microsoft's SQL Server, for which it is a kind of marketing tool.

The issue is nicely expressed here, by DevOps engineer Michael Hoagland: "If you want to let your applications actually use even a fraction of what you’re paying those huge licensing fees for, stop constraining SQL to an EF driven hellish wasteland of something little better than SELECT *."

Hoagland argues that EF can be used efficiently, but that this is rarely the case, in part because Microsoft's documentation leads developers down the wrong path.

Developers in search of better performance may wish to look at Dapper, a thin object mapper for .NET that requires developers to know their SQL, but in return delivers much faster results.

StackOverflow survey shows that while developers enjoy working with ASP.NET, it doesn't appeal strongly to those not yet using it

The most recent StackOverflow technology survey shows ASP.NET used by 26.3 per cent of respondents, scoring 64.9 per cent for "most loved" and 35.1 per cent for "most dreaded." These are not bad figures, but most telling is that the platform scores only 3.7 per cent under "most wanted,” supporting a suspicion that while Microsoft’s move towards open source and cross-platform with .NET Core and ASP.NET Core have helped developers like Gordon stay on board with the company’s web platform, it has not been so successful in attracting new developers from elsewhere. One of the issues, perhaps, is that Microsoft tends to present it as part of a package including Entity Framework, SQL Server and even Azure. That must be good for product adoption, but does conflict with its effort to appeal to a wider community. ®

Sign up to our NewsletterGet IT in your inbox daily

32 Comments

Keep Reading

Microsoft Visual Studio gets .NET Core debugging – on WSL2

Hands On 'Higher fidelity local debugging experience' than debugging on Windows and deploying to Linux

Microsoft boffin inadvertently highlights .NET image woes by running C# on Windows 3.11

Old? Windows-only? Community struggles with '40-year-old male' problem

Microsoft starts a grand unification attempt with .NET 5

Preview 1 hints at great things, but right now has just enough to make ARM64 users smile

.NET Core: Still a Microsoft platform thing despite more than five years open source

Comment Making .NET cross-platform was a radical step but not enough for broad appeal

Oh, you shouldn't have: Microsoft whips up website for devs that makes it easier to moan about Windows issues

Just be careful it's not 'out of scope'

Microsoft throws a bone to those unable to leave the past behind: .NET 5 support on the way for Visual Basic

But you should really be looking at migrating to C#

Are you having a hard time following what Microsoft is trying to do with .NET 5.0? You're not the only one

'Even as the release blog writer, I find this difficult'

Microsoft Web Live Preview: Hot reload for ASP.NET web applications

New time-saving extension works only with old .NET Framework, for now

Amazon Web Services joins Google in paying lip service to Microsoft's .NET platform

With the hope of running more enterprise applications

Project Reunion: Microsoft's attempt to tear down all those barriers it's built for Windows developers over the years

Build Plus: Bye-bye Xamarin Forms, hello Multi-Platform App UI, for when Universal is not universal enough

Tech Resources

The Cloud: How CISOs Can Embrace It (Wisely), Not Fear It

Cloud computing is one of the great transformational shifts in corporate information technology.

Simplifying Hybrid Cloud Flash Storage

According to industry analysts, a critical element for secure hybrid multicloud environments is the storage infrastructure.

Navigating the New Era of Cloud Computing

Hear from Steve Sibley, VP of Offering Management for IBM Power Systems about how IBM Power Systems can enable hybrid cloud environments that support “build once, deploy anywhere” options.

Quit your addiction to storage

Traditional storage management won’t cut it with today’s massive data growth.