Peter Morlion logo

Generating a JWT in .NET 4.5.2

I recently had to generate a JSON Web Token (JWT) as a response from an login request to an api. The idea is to POST the user’s credentials from a mobile app, and to respond with a JWT. The mobile app can then verify that the user has logged in correctly. A quick introduction to […]

RedStar.Amounts ported to .NET Standard 2.0

Almost a year ago now, I introduced RedStar.Amounts, a .NET library to handle units and amounts in an easy way. The code It allows you to explicitly state what unit a certain amount is measured in. So instead of doing this: var lengthInCm = 400; You can do this: var length = new Amount(400, LengthUnits.CentiMeter); […]

A private feed for your organization via AppVeyor

If you’re working in the .NET stack regularly and don’t know AppVeyor yet, it’s definitely worth checking out. AppVeyor is a CI system focused in .NET projects. You can easily link it to GitHub, Bitbucket and Visual Studio Online. It can build your project, run tests, deploy, and… publish to NuGet. This is what I […]

Introducing RedStar.Amounts

How many times have you had to ask a colleague what unit that external application is using? Or worse, had bugs because you forgot to divide by 100? In many applications, it is common to change values when they are received by dividing or multiplying them. This is done because the other application uses centimeters, […]

C# string magic

In C#, you need strings often. Less often, you need a long string, but it still happens. So here’s a nice thing to know. You can split them over multiple lines without need the + operator and an Environment.NewLine call. What you need is a verbatim string literal. Those start with an @: @”c:\Docs\Source\a.txt” // […]

Running ASP.NET (not Core) from NPM

I’m currently working on a NodeJS project that makes HTTP calls to an ASP.NET (4.5.1) application. When running locally, I also want to make these calls to my local ASP.NET application. Sometimes, however, I don’t want to start up Visual Studio, open the project, compile, and run. Seeing as this is not ASP.NET Core, I […]

Moving from ES5 to ES2015 in ASP.NET

Have an old(er) ASP.NET project where javascript files put all their functions and variables in the global namespace? Want to move to modern javascript (ES2015) with dynamic module loading? If you don’t know where to begin, this guide might be able to help you. I was facing the same issue in an ASP.NET project (MVC, […]

Integration testing in-memory WebAPI with Autofac

Continuing on my previous post on WebAPI, Autofac and filters, I now want to add an integration test. Unit testing WebAPI controllers is no different than testing other pieces of code. Just inject mocks in the constructor and you’re good to go. Integration testing can be as simple, if you’re not using filters. The filters […]

Autofac, Web API and filters

A short post with a small, useful tip. It’s mainly for my future self, but may be good to know for you too. If you’re using ASP.NET Web API, you might have controllers that look like this: public class CustomerController : ApiController { private readonly ILog _log; public CustomerController(ILog log) { _log = log; } […]

Automating your NuGet package

NuGet is a great way of handling dependencies. It isn’t perfect, but if you’ve experienced the days of DLL hell, you know NuGet hell is at least more manageable. One step that I’ve found was always missing, is automating the publishing of your NuGet package. We’ve played around with different scripts in the past, bat […]