Contents tagged with dotnet-core

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

    } … more

  • 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( … more

  • Dot net on Docker at Dot Net North

    I miss going to usergroups, 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 … more

  • 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. … more

  • 1