• The best way to implement INotifyPropertyChanged in .NET Maui

    This is the best way that I've discovered to implement INotifyPropertyChanged in a XAML based MVVM app without downloading any extra supporting code.It relies on the ref keyword to allow a method in the base class to modify the property that you wish to raise a property changed event for. The code is fairly concise and it doesn't add any unseen overhead.

    In your view model all you need to do is:

    namespace Nogginbox.MyApp.ViewModels;

    public class MyViewModel : ObservableViewModelBase

    {

    public string Name

    {

    get => _name;

    set => SetProperty(ref _name, value);

    } …

  • Generating links inside a .NET Core Tag Helper

    Previously when generating links inside any non view code I'd always try and get hold of an instance of IUrlHelper, but I've found a simpler way that has been available since .NET Core 2.2.

    LinkGenerator can be injected into a tag helper or any class. It has all the useful methods of IUrlHelper, with fewer dependencies. It only asks for HttpContext if it absolutely needs it, which in many cases it does not.

    Inject it into your class like so:

    private readonly LinkGenerator _linkGenerator;

    public NogginTagHelper(LinkGenerator linkGenerator)

    {

    _linkGenerator = linkGenerator;

    }

    Using the …

  • Using URL helper inside your .NET Core Tag Helper

    I've discovered a better way of doing this. Check out my new post on using LinkGenerator instead.

    If you're writing a tag helper and would like to generate links using IUrlHelper then you can not inject this directly. You need to inject an IUrlHelperFactory and then there are a few hoops that you need to jump through.

    This is how to set up the UrlHelper inside you tag helper constructor:

    private readonly IUrlHelper _urlHelper;

    public NogginTagHelper(IUrlHelperFactory urlHelperFactory, IActionContextAccessor contextAccessor)

    {

    _urlHelper = urlHelperFactory.GetUrlHelper(contextAccessor. …

  • .NET on Docker at Dot Net North

    I miss going to user groups, but with all the videos online now it is does mean I can get to more of the slightly further away user groups like Dot Net North. Even if I don't get to talk to anyone there.

    I first saw Docker being used by a developer in my co-working space for his Dating Site Whitelabel platform. The platform's userbase was growing and he was experimenting with different infrastructures to help support that growth. Docker enabled him to set up test environments that would be identical to the final production environment, to set them up quickly and repeatedly. He found this …

  • Installing a free SSL Cert on your IIS .NET Core MVC website

    SSL certs are getting more and more important on the web as we want to make sure that our websites are safe and trustworthy. I’ve put off installing them on my own personal web site projects because of the cost and the work involved in keeping them up to date.

    Let’s Encrypt is an open Certificate Authority that is trusted and issues free 3 month certificates. They have an API that lets you automate getting these certificates and there are several tools for Linux and Windows that use this API to save you the work of installing and keeping your certs up to date.

    I used the Windows tool Certify …

  • Forms Authentication in .NET Core (AKA Cookie Authentication)

    In .NET Core MVC you're encourages to use .NET Identity, but you don't have to. You can manage your own user identities and you use forms authentication which is now called Cookie Authentication (which is a better name really).

    You need to install the Microsoft.AspNetCore.Authentication.Cookies nuget package.

    There is some configuration that needs to go in startup.cs:

    public void ConfigureServices(IServiceCollection services)

    {

    services

    .AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)

    .AddCookie(options => {

    options.AccessDeniedPath = "/ …