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 JWT But let’s step out for a moment. What is a JWT exactly? According to jwt.io, a JSON Web Token is an open, industry standard

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); What’s more, you can perform calculations without having to wonder what the unit is: var length = new Amount(1000, LengthUnits.CentiMeter); var width = new Amount(1,

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 will cover in this post today. When you have a piece of code that is repeated across two or more projects, it can be interesting,

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, while our application uses meters, or some similar difference. There are libraries that mitigate this, but I didn’t find one to my liking. I’ve used

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” // rather than “c:\\Docs\\Source\\a.txt” But the extra nice thing is they can span multiple lines, making them easier to read: @”Hello This is text on a

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 can’t just run it from the command-line. Or can I? It turns out that if you have IIS Express installed (which you should have, with

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, but it should be possible for WebForms too). It’s actually quite simple. We’ll go from this: Browser loads a page Browser loads all included javascript

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 can, however, add interesting behavior to your controllers, like the exception handling I explained in my previous post. To fully test this, you will have

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; } [HttpGet] public HttpResponseMessage GetCustomer(int customerId) { try { } catch (Exception e) { _log.Error(e); return Request.CreateResponse(HttpStatusCode.InternalServerError); } } } Two things can make your code

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 files and PowerShell files, but it was always a bit hacked together. And it always required several manual steps when a new project was created.