Developing Websites with ASP.NET Core Razor Pages — Visual Studio Magazine

Questions and answers

Q&A: Developing Websites with ASP.NET Core Razor Pages

Microsoft says developing Razor Pages in ASP.NET Core can make coding page-centric web development scenarios easier and more productive than using controllers and views built into another option: the Model approach. View Controller (MVC).

Specifically, the company’s documentation states, “Razor Pages is a page-based model. UI and business logic issues are separate, but within the page. Razor Pages is the recommended way to create new page or form-based applications for developers new to ASP.NET Core. Razor Pages provides an easier starting point than ASP.NET Core MVC.”

ASP.NET Core Razor Pages
[Click on image for larger view.] ASP.NET Core Razor Pages (source: Microsoft).

To help .NET-centric developers get started building web projects with this approach, Microsoft MVP Philip Japikse is hosting a mid-level and full-stack development session at the major Live!360 tech conference to be held in Orlando from November 13 to 18.

Attendees of the November 15 presentation titled Websites with ASP.NET Core Razor Pages will dig deeper into the details of display components, tag helpers, routing, and more in the 9:15-10:30 session.

We caught up with the renowned international speaker to get more details about the session in a short Q&A.

Visual Studio Magazine: Can you briefly explain the basics of ASP.NET Core?
Japan: ASP.NET Core is the next evolution of web development using the Microsoft stack. Based on .NET (Core), ASP.NET Core is a complete re-architecture and rewrite of the hugely popular ASP.NET framework. ASP.NET Core not only focuses on developer productivity, but also on performance. With each release of ASP.NET Core, benchmarks place the framework among the fastest available. With ASP.NET Core, you can develop RESTful services, web apps (using Razor Pages or the Model View Controller (MVC) pattern), and single-page apps (SPAs) using Blazor.

What are your favorite new features in ASP.NET Core Razor Pages?
For me, the reason I love Razor Pages is twofold. The first is Razor’s familiar view engine. If you’ve worked in MVC applications before, many of the features will come very naturally to you: page layout, templates (view and editor), and the benefit of being able to stay in markup with Razor. The second is the speed of web application development.

“Because Razor Page-based apps are page-centric and don’t use the MVC pattern, each page can stand alone. This creates a lower barrier to entry than its MVC counterpart, and I find that works great for small applications.”

Philip Japikse, Microsoft MVP, ASPInsider, MCSD, PSM II, PSD and PST

Because Razor Page-based apps are page-centric and don’t use the MVC pattern, each page can stand alone. The Get and Post routing methods and parameters are in the view’s code-behind file. It creates a lower barrier to entry than its MVC counterpart, and I find it works very well for small applications.

What new features would you like to see in ASP.NET Core Razor Pages?
The only part of Razor Page-based web applications that prevents us from using them at scale in large applications is the friction needed to achieve code reuse through inheritance. while you box technically creating a base page and inheriting from it into your Razor Pages, there isn’t the level of support and reuse that you get when developing an enterprise application using the MVC pattern.

What issues do developers typically encounter when getting started with ASP.NET Core Razor Pages?
If you’ve used ASP.NET MVC in the past, you’ll be very comfortable with the Razor View Engine. I think the biggest challenge will be getting back into a page-based routing system and getting used to code-behind files again. Code-behind files have a rather nasty legacy, and MVC developers will have to move past the history and embrace the new. Much care has been taken in Razor Pages to avoid code-behind file errors in ASP.NET Web Forms.

If you come from a Web Forms background, the Razor view engine is quite different from the Web Forms view engine. Although vastly improved, it will take some getting used to. While there are familiar patterns (like basic layout pages and a page-based routing engine), moving from Web Forms to ASP.NET Core is probably a bigger leap than moving from ASP.NET MVC to Razor Page based applications.

While Blazor caused a stir by allowing C# web development, what is the role of ASP.NET Core Razor Pages amid all the Blazor hype?
It’s not really a question of one over the other. They are very different and offer different mechanics. ASP.NET Core web apps using Razor Pages or the MVC pattern use server-side code combined with the Razor view engine, HTML markup, and client-side code (CSS/JS) to render a complete end-to-end app . The way authentication and authorization “just works” has some advantages, and there are features that help defend against cross-site scripting attacks. Blazor WebAssembly (or Blazor Wasm), on the other hand, is a Single Page Application (SPA) framework that runs entirely on the client (much like a JavaScript-based SPA).

A Blazor app will need a RESTful service to provide its data, authorization/authentication, etc. One of the reasons some developers really like Blazor is that it drastically minimizes the JavaScript you have to write and instead lets you write a lot of the client-side logic in a language you might be familiar with. be more comfortable, like C#. There are of course compromises. For example, security is a very different paradigm than Razor Pages or MVC. Now you are considering using openID connect, OAuth or another token-based system instead of “out of the box” ASP.NET Identity. Note that this is no different than if you were using Angular to build your application, as the same security issues exist. But for many C#/ASP.NET (Core) developers, this would be a whole new requirement to solve. I’m not saying one is better than the other, but they are very different paradigms in many development and deployment details.

If you were to follow up your question with “which is better”, I would answer that Blazor and Razor Pages are very solid, even as new as Blazor WebAssembly. The best part of the discussion is that now, as a developer based on the Microsoft stack, you have many different choices on how to build your apps.

About the Author


David Ramel is an editor and writer for Converge360.



Comments are closed.