Latest Entries

Localising Data Annotation Attributes in Razor Pages

calendar_today 17 December 2019 07:33

ASP.NET Core Razor Pages Localization

This is the third article in a series that explores various aspects of localisation in ASP.NET Core Razor Pages applications. The first article looked at how to work with cultures, and the second covered the basics of using resource files for static content translations. In this article, I explain how to provide localised resources for form labels and validation error messages for PageModel properties that have Data Annotation attributes applied to them.

Using Resource Files In Razor Pages Localisation

calendar_today 10 December 2019 07:50

ASP.NET Core Razor Pages Localization

This is the second in a series of articles that cover localisation in ASP.NET Core Razor Pages applications. In the previous article, I looked at the basic configuration required to work with cultures which are the basic building block of localisation. I showed how to specify the cultures that the application supports, how to set the culture for the current request, and how some items, such as calendars are translated depending on the current culture. This article builds on the application which was introduced in the the last article and explores how to configure and use resources to store translated versions of static content.

Localisation in ASP.NET Core Razor Pages - Cultures

calendar_today 03 December 2019 07:50

ASP.NET Core Razor Pages Localization

This is the first in a series of articles that explores localisation in ASP.NET Core Razor Pages applications. This article will look at the configuration required to prepare a site for content localisation, in other words, to globalise the site. Future articles will cover the creation of localised content and how to present it.

What Happened To @Helpers In ASP.NET Core?

calendar_today 21 November 2019 13:11

ASP.NET Web Pages Razor ASP.NET Core Razor Pages

When you port your Razor-based application to ASP.NET Core, whether its an MVC application or a Web Pages application, you might notice that adding a @functions block to your .cshtml file works as expected, but any attempt to add a @helpers block doesn't work at all.

Improved Remote Validation in Razor Pages

calendar_today 13 November 2019 07:51

ASP.NET Core Razor Pages

Remote Validation is a technique that uses client side script to validate user input on the server without posting the entire form. Remote validation has always been possible in Razor Pages using either the RemoteAttribute, which requires an MVC controller to work, or by writing custom client-side script. One almost completely overlooked feature that was included in ASP.NET Core 3.0 was the introduction of a Razor Pages-specific validation attribute that removes this reliance on MVC controllers or custom code for remote validation.

Managing Authentication Token Expiry In WebAssembly-based Blazor

calendar_today 05 November 2019 13:50

ASP.NET Core Blazor

The Blazor WebAssembly project template doesn't feature an option to include authentication. If you want to add authentication to a WebAssembly-based Blazor application, you need to do it yourself. This article shows how to add application-wide authentication management and then to use built-in Razor components to protect the FetchData page in the standard template from unauthorised users.

Uploading Files In Blazor

calendar_today 17 October 2019 07:47

ASP.NET Core Blazor

A few weeks ago, Steve Sanderson blogged about publishing a package for a prototype Blazor file input component, designed to make working with user-supplied files in Blazor applications a lot easier. Steve has provided some very clear examples demonstrating how to use the component in a number of scenarios. Missing, though, is an example showing how to make an HTTP request to upload a file to some back-end server from a Blazor WebAssembly application.

Working With Query Strings In Blazor

calendar_today 11 October 2019 12:44

ASP.NET Core Blazor

When passing data in a URL within a Blazor application, most of the time you will define route templates that incorporate parameter placeholders, passing values as URL segments. You might also find that you need to be able to work with query string values, so how do you do that in a Blazor application?

Optional Parameters in Razor Pages Routing

calendar_today 21 August 2019 20:11

ASP.NET Core Razor Pages

Razor Pages routing is based on attribute routing and is very powerful. Parameters provide a way of passing arbitrary data to a page via the URL. Optional parameters allow URLs to matched to routes even if no parameter value is passed. Things can get a bit complicated if you want to permit multiple optional parameters.

Using Razor Components In A Razor Page

calendar_today 05 August 2019 12:40

ASP.NET Core Razor Pages Blazor

In my last article, I looked at some of the new things that ASP.NET Core 3.0 will introduce to Razor Pages developers. One of the features that I touched on was Razor Components. In this article, I take a more detailed look at what they are and how they can be used.

What's New In .NET Core 3.0 For Razor Pages

calendar_today 24 July 2019 19:44

ASP.NET Core Razor Pages Blazor

Later this year, .NET Core 3.0 will be released. The main features include WPF and Windows Forms support (albeit only on the Windows operating system) and server-side Blazor. Razor Pages applications will also see some changes. I cover some of these as part of a guide to upgrading an application from 2.2 to 3.0. Then I have a quick look at some of the other new features. Note that the information in this article is based on Preview 6, and is subject to change.

AJAX Posts In Razor Pages And HTTP 400 Errors

calendar_today 15 July 2019 12:41

ASP.NET Core Razor Pages

Every other day or so it seems, a new question is posted to one of the community forums that cover ASP.NET Core Razor Pages asking why an AJAX post doesn't appear to work, or results in an HTTP 400 error. This article explains the most common cause, and offers guidance on how to solve it.

Simple Authentication In Razor Pages Without A Database

calendar_today 08 May 2019 07:26

ASP.NET Core Razor Pages ASP.NET Identity

Sometimes, using the full ASP.NET Core Identity framework is overkill for small, one-user applications that require some form of authentication. I'm thinking about blog applications, or web-based utilities that have admin areas that only you should be allowed to reach. All you really want to do is authenticate against a user name and password stored in a config file or similar. You really don't need the ceremony of a database, EF Core, ApplicationDbContexts, SignInManagers, UserManagers etc. This article provides a step-by-step guide to implementing simple authentication using just cookies, while storing credentials securely without a database.

Using Parameter Transformers To Modify Route And Parameter Values In Razor Pages

calendar_today 29 April 2019 08:45

ASP.NET Core Razor Pages

Available from ASP.NET Core 2.2, parameter transformers enable the centralisation of logic for modifying the value of routes and route parameters in URLs generated by the anchor tag helper or the Url helper.

Creating Custom Constraints For Razor Pages Routes

calendar_today 01 April 2019 09:16

ASP.NET Core Razor Pages

Razor Page already includes a wide range of constraints that can be used to help disambiguate routes. It is also possible for you to create your own custom constraint and then register that with the routing system.

Rendering A Partial To A String In Razor Pages

calendar_today 19 March 2019 08:22

ASP.NET Core Razor Pages

Partial Views or Pages are primarily used as a means of including reusable snippets of HTML within one or more Razor Pages. This walkthrough illustrates how to take advantage of the power of the Razor templating system used by partial pages to generate HTML for other purposes, such as the body of a mail message.

Global Error Handling And Logging With NLog In Razor Pages

calendar_today 12 February 2019 08:26

ASP.NET Core Razor Pages

Exceptions in .NET represent an error condition in an executing program. Error conditions can come about as a result of a large number of causes, each represented by its own exception type. Most exceptions arise from logical errors in code, such as an attempt to work with an object that has not been instantiated (NullRefrenceException), or to divide by zero (DivideByZeroException). Other types of exceptions result from technical issues, which may or may not be temporary. Examples of such issues might include a database or mail server being unavailable, or insufficient file system permissions.

Including Static Resources In Razor Class Libraries In ASP.NET Core

calendar_today 17 October 2018 13:32

ASP.NET Core Razor Pages

Razor Class libraries (RCLs) were introduced in ASP.NET Core 2.1 as a way to package and distribute UI components to be referenced and consumed within a host application. You can see them as a fully functioning part of a web application packaged as a class libray. The templated management pages for ASP.NET Identity were included as a Razor Class Library in the project template in 2.1. The Identity UI RCL includes the Razor pages, Filters, a stub EmailService class that Identity uses, and local versions of both Bootstrap 3 and 4.

Adding Sorting To Paging In ASP.NET Core Razor Pages

calendar_today 10 October 2018 08:35

ASP.NET Core Razor Pages

This article builds on the simple paging functionality that was added to a Razor Pages application in my last article by showing how to add sorting functionality so that the user can determine the order in which results are displayed.

Simple Paging In ASP.NET Core Razor Pages

calendar_today 03 October 2018 07:49

ASP.NET Core Razor Pages

This article attempts to demonstrate how to implement simple paging functionality in a Razor Pages application. I will explain the basics behind paging, and then use BootStrap 4 to render a variety of paging links, without resorting to Nuget packages for link generation.