Mikesdotnetting News FeedLatest additions to Mikesdotnettingurn:uuid:5f7fe613-2d22-47b0-9d9b-688e73e93a94;id=1(c)2024, Mike Brind. All rights reserved2023-10-10T06:03:52ZMike Brindhttps://www.mikesdotnetting.com/article/367/working-with-sass-in-an-asp-net-core-applicationWorking with Sass in an ASP.NET Core applicationSass (Syntactically Awesome Style Sheets) is a is a scripting language that is used to generate cascading style sheets (CSS files). Its syntax is very
similar to CSS itself, but it supports the use of variables, nesting, mixins and selector inheritance, none of which are available in CSS itself.
However, these features help you to organise and maintain your web
application's styles. In this article, I look at the steps required to incorporate and configure Sass in your ASP.NET Core project in both Visual Studio, and VS Code.2023-06-02T06:50:59+01:00Mike Brindhttps://www.mikesdotnetting.com/article/366/why-doesnt-my-asp-net-core-7-web-app-launch-on-httpsWhy doesn't my ASP.NET Core 7 web app launch on HTTPS?Up until .NET 7, when you use the <code>dotnet run</code> command to run your ASP.NET Core Razor Pages (or MVC) app, the built-in Ketstrel web server would listen on two URLs, one with a
<code>http</code> protocol and another that uses the <code>https</code> protocol. This behaviour is documented in many places (<a href="https://www.manning.com/books/asp-net-core-razor-pages-in-action?utm_source=mikebrind&utm_medium=affiliate&utm_campaign=book_brind_razor_7_26_21&a_aid=mikebrind&a_bid=f71bcc8c">including my book</a>) so it might come as a surprise when
you run your new .NET 7 app from the command line and it is only available on an
<code>http</code> binding. Something changed in .NET 7. What is it and how do you test your .NET 7 web app under
<code>https</code>?
2023-03-20T01:37:26+00:00Mike Brindhttps://www.mikesdotnetting.com/article/365/executing-async-operations-onchange-in-blazorExecuting async operations onchange in BlazorBlazor's <a href="https://www.learnblazor.com/data-binding">two-way databinding model</a> is extremely powerful, but sometimes
it can get in the way of what you want to do. For example, you might
want to execute an asynchronous operation such as remote validation when a value changes in a
textbox. Perhaps you want to check instantaneously that the value - a username maybe -
doesn't already exist in a database before you accept a new
registration. You cannot add an <code>onchange</code> event handler if
you already have a value bound to the element, so what can you do? In this
article, I look at solutions for both HTML elements and EditForm input
validation components up to an including .NET 7, and a new
feature released in .NET 7.0.1.2023-02-15T09:32:57+00:00Mike Brindhttps://www.mikesdotnetting.com/article/364/exploring-generating-pdf-files-from-html-in-asp-net-coreExploring generating PDF files from HTML in ASP.NET CoreBack in 2008, I wrote a
<a href="https://www.mikesdotnetting.com/category/20/itextsharp">series of articles
about using iTextSharp to generate PDF files in an ASP.NET application</a>. I
still use iTextSharp in a large MVC 5 application that I'm in the process of
<a href="https://www.mikesdotnetting.com/article/360/incrementally-migrating-an-asp-net-framework-application-to-razor-pages">
migrating to ASP.NET Core</a>. The version I use is very old (4.1.6), and the
API is very low level so it takes quite a while to write the code required to generate
even a moderately complex PDF. Ideally I need a replacement for the new
application that can generate PDF files purely from HTML, which is an API I'm
much more comfortable with. This ancient version of iTextSharp doesn't support
HTML as a source of content. In this article, I consider some alternatives.2022-11-30T01:45:51+00:00Mike Brindhttps://www.mikesdotnetting.com/article/363/a-reusable-generic-autocomplete-component-for-blazorA reusable generic autocomplete component for BlazorIn
<a href="https://www.mikesdotnetting.com/article/362/simple-autocomplete-for-blazor">
my last article</a>, I looked at building a simple autocomplete component within
a Blazor WebAssembly application that fetches data dynamically from a database
via an API depending on what the user enters into an input. It works nicely but
it has not been designed to be reusable. In this article, I look at the steps required to convert the
component so that it can be plugged in anywhere within an application and work
with any kind of data.2022-11-17T01:14:18+00:00Mike Brindhttps://www.mikesdotnetting.com/article/362/simple-autocomplete-for-blazorSimple Autocomplete for BlazorOne of the things I really like about Blazor is how often it is easy to implement
features in your application that, if needed in a server-side application, would have you testing your JavaScript-fu or
reaching for a third party component. One example is an autocomplete component
that fetches live data from a database that matches that which a user enters
into a form control and changes as the user types. In this
article, I'll show how to build such a component for a Blazor WebAssembly app
and style it like a dropdown.2022-11-08T08:49:37+00:00Mike Brindhttps://www.mikesdotnetting.com/article/361/resize-images-before-uploading-in-blazor-web-assemblyResize images before uploading in Blazor Web AssemblySo, you allow users to upload images to the server from your Blazor WASM app, but you
want to constrain the actual dimensions of the image for some reason. Rather than ask the user to edit the image prior to uploading, you decide to to take care of applying this requirement within the application. And you further decide to do any resizing in the browser
<em>prior</em> to uploading so that the resulting upload is smaller and you don't have to waste server resources on the procedure. In this article, I take a look at how to do that, and how to get the dimensions of an image file.2022-10-31T02:03:44+00:00Mike Brindhttps://www.mikesdotnetting.com/article/360/incrementally-migrating-an-asp-net-framework-application-to-razor-pagesIncrementally Migrating an ASP.NET Framework application to Razor PagesDo you have a huge .NET framework application (Web forms, MVC) that
relies on authentication and/or System.Web types that you would
ideally like to migrate to .NET Core, but just don't have the bandwidth to put
everything on hold while you rewrite the entire application on a new framework?
If so, you might be interested in an exciting new project from Microsoft -
<a href="https://github.com/dotnet/systemweb-adapters">SystemWebAdapters for ASP.NET Core</a>
- that enables you to incrementally migrate your old application, endpoint by
endpoint.2022-10-11T01:41:10+01:00Mike Brindhttps://www.mikesdotnetting.com/article/359/strongly-typed-middleware-in-asp-net-coreStrongly Typed Middleware in ASP.NET CoreMost ASP.NET Core developers are familiar with the traditional way to author
middleware classes which is based on conventions. The vast majority of examples
out there feature the convention-based approach. But
there is also a strongly typed approach available which is based on implementing
the <code>IMiddleware</code> interface. This seems to be one of ASP.NET Core's
best kept secrets, so I thought I'd pull the curtains back and let some light
shine on it.2022-08-24T12:30:51+01:00Mike Brindhttps://www.mikesdotnetting.com/article/358/using-minimal-apis-in-asp-net-core-razor-pagesUsing Minimal APIs in ASP.NET Core Razor PagesIf you are using ASP.NET Core Razor Pages to develop your web
application, you have already decided that the majority of your HTML
will be generated on the server. Nevertheless, chances are that you will
want to introduce some client side operations into the application to
improve its user friendliness in places. If those operations involve
data, you will probably want to work with JSON. From .NET 6, you can use
a simplified minimal request handler API that works with JSON by
default.2021-12-14T01:33:30+00:00Mike Brindhttps://www.mikesdotnetting.com/article/357/razor-pages-startup-in-net-6Razor Pages Startup in .NET 6When you create a new web app using .NET 6 (from the new RC1 templates), you might notice something is missing. There is no Startup class. What happened to it? And how do you configure your new .NET 6
web app?2021-10-08T08:34:09+01:00Mike Brindhttps://www.mikesdotnetting.com/article/356/i-am-writing-a-book-about-razor-pagesI am writing a book about Razor PagesJust over three years go, when Razor Pages was first launched, I had a number of questions from people asking whether I was going to write a book about the Razor Pages framework. I guess they asked me because Razor Pages appeared to be a natural successor to the old ASP.NET Web Pages framework, and I had written a book about that. Also, I was regularly blogging at the time about all the good things you could do with Razor Pages. <a href="https://www.mikesdotnetting.com/article/314/im-not-writing-a-book-on-razor-pages">The answer then was No</a>, primarily because I was working on my own tutorial/documentation site
for Razor Pages - <a href="https://www.learnrazorpages.com/">learnrazorpages.com</a>.2021-11-24T03:35:38+00:00Mike Brindhttps://www.mikesdotnetting.com/article/355/css-isolation-in-razor-pagesCSS Isolation In Razor PagesCSS isolation was introduced in .NET 5 for Blazor components. Now it's coming to Razor Pages (and MVC views) in .NET 6, due to be released in November this year. Here's a quick look at
how CSS isolation works in Razor Pages and the kind of problem that it's designed to solve.2023-03-23T09:03:57+00:00Mike Brindhttps://www.mikesdotnetting.com/article/354/implementing-a-custom-typeconverter-in-razor-pagesImplementing a Custom TypeConverter In Razor Pages In my most recent article, I showed
<a href="https://www.mikesdotnetting.com/article/353/implementing-a-custom-model-binder-in-razor-pages">how to create a custom model
binder</a> to bind an ISO 8601 string representation of a week of the year
to a <code>DateTime</code> type in a Razor Pages application. The custom
model binder leant heavily on the existing infrastructure that binds
strings to simple types. Custom model binders are the correct solution
if you want to bind to simple types, but if you want to bind to a
complex type, the recommendation is to implement a <code>TypeConverter</code>
<a href="https://docs.microsoft.com/en-us/aspnet/core/mvc/advanced/custom-model-binding?view=aspnetcore-3.1#recommendations-and-best-practices">
according to the offical docs</a>. But the docs don't provide an example
that shows how to do that in the context of model binding. So here's
one.2020-11-24T06:34:21+00:00Mike Brindhttps://www.mikesdotnetting.com/article/353/implementing-a-custom-model-binder-in-razor-pagesImplementing a Custom Model Binder In Razor PagesIn Razor Pages, model binding is the process that maps data from an HTTP request to
simple PageModel properties or handler parameters.
Incoming data can be included in a request as posted form values, query
string values or route data. The default collection of model binders cover
every simple .NET data type.. But sometimes they are not enough, and you need to add
your own implementation.2020-11-10T03:28:04+00:00Mike Brindhttps://www.mikesdotnetting.com/article/352/working-with-dates-and-times-in-razor-pages-formsWorking with Dates And Times in Razor Pages FormsWhen working with dates and times in a Razor Pages form, you need to render
a suitable control based in the task requirement. Prior to HTML5, developers
largely depended on third party date picker libraries. Now, a variety of native
browser options
exist, although they enjoy <a href="https://caniuse.com/?search=date%20and%20time">
varied support across modern browsers</a>. These include options for
managing the date and time, just the date or time, and for working with the
month or week of the year. 2021-06-29T06:23:08+01:00Mike Brindhttps://www.mikesdotnetting.com/article/351/display-images-in-bootstrap-carousel-using-razor-pages-and-entity-frameworkDisplay Images in Bootstrap Carousel using Razor Pages and Entity FrameworkThis short article shows how to display images stored in a database in a Razor Pages application using the Bootstrap Carousel and Entity Framework Core.2020-06-19T03:37:02+01:00Mike Brindhttps://www.mikesdotnetting.com/article/350/razor-pages-and-bootstrap-lazy-loading-tabsRazor Pages And Bootstrap - Lazy Loading TabsTabbed interfaces are a great way for managing the presentation of large amounts of information into separate panels, where each panel's data makes sense on its own, and only one panel is viewable at a time. The tabs in a browser are a great example of this. From a Razor Pages developer's point of view, tabs are particularly useful for controlling the display of complex data in Line Of Business applications.2020-06-10T12:34:23+01:00Mike Brindhttps://www.mikesdotnetting.com/article/349/razor-pages-and-bootstrap-modal-master-detailsRazor Pages And Bootstrap - Modal Master DetailsThis is the first in a series of posts exploring how to use some of the
components provided by Bootstrap within a database-driven Razor Pages web
application. In this article, I look at using the Bootstrap Modal in a
Master/Details scenario, to display the details of the selected record in a
master list.2023-10-10T07:03:52+01:00Mike Brindhttps://www.mikesdotnetting.com/article/348/razor-pages-localisation-seo-friendly-urlsRazor Pages Localisation - SEO-friendly URLsThis is the fourth article in a series that explores various aspects of localisation in ASP.NET Core Razor Pages applications. This article concentrates on the SEO aspects of localisation as they pertain to URL management, and how to utilise the RouteDataRequestCultureProvider to help you manage that. 2020-01-07T07:39:46+00:00