Software

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

Too many choices?

Got Tips? 32
SHARE

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 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

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#

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

Microsoft emits long-term support .NET Core 3.1, Visual Studio 16.4

Ready to go, but beware 'unfortunate breaking change' in Windows Forms

Long after Linux, Windows Server Containers finally arrive on Microsoft's Azure Kubernetes Service

Generally available, but will never reach parity with Linux on Kubernetes

Microsoft says .NET Framework porting project is finished: If your API's not on the list, it's not getting in

Unless you ask really nicely

Microsoft throws lifeline to .NET orphans in the brave new Core world

It is acronym Monday as WCF and WF get OSS projects

Microsoft brings WinUI to desktop apps: It's a landmark for Windows development, but it has taken far too long

Hands On The look and feel of UWP without all the baggage

Tech Resources

Webcast Slide Deck | How to simplify data protection on Amazon Web Services

The way we backup and restore has changed, but the outcomes are often just as bad. If you’re waiting hours to restore, or keeping terabytes of data because you don’t know if you can delete it, you’re wasting your time and your money. So imagine a service that restores in seconds, even individual files. Join Sebastian Straub, N2WS’s “personable IT magician” and Danny Michael, Head of IT at Gett, who promise to show us a better way in a live Regcast.

Ransomware Hostage Rescue Manual

Free your files! Get the most informative and complete hostage rescue manual on ransomware.

Detect Threats Early and Follow Attacker Movement Across the Network

The addition of Network Traffic Analysis to InsightIDR means teams have all of their critical security data in one place.

2020 SANS Network Visibility and Threat Detection Survey

Read the report to learn how to do more with the network data you already have and what to look for in a network visibility tool.