Category Archives: Coding

Norwegian personal number verification in C#

Code to verify Norwegian personal number (personnummer / fødselsnummer) written in C#. Obeys 2013 standards as described in this Wikipedia article. Please let me know how if you find bugs / improvements. :)

(PS: This code is easy to test in LINQPad. Select C# Program, paste it in and hit run.)

C# Regex for verifying e-mails

Regex for matching e-mail in C#. Came across http://emailregex.com/ which has a horrible example, so ended up making my own loosely based on that. It leaves much to be desired, but will cover most use cases well enough.

   

ASP.Net 5 Identity Framework 3.0 manually adding users

Identity Framework 3 is in release candidate along with ASP.Net 5. The problem I set up a web project in ASP.Net 5 and created a controller for user import. It’s just some simple code that attempts to add multiple users. Adding a single user works great, but if I attempt to perform multiple operations in… Read More »

ASP.Net 5 Areas

Visual Studio 2015 with ASP.Net 5 doesn’t support Areas in the GUI editor. Hopefully that will come, but until then here is a simple workaround. Create folder structure In the root of your project (not wwwroot) create the folder structure for Areas manually. In this example I created an area named “Foobar”. Edit Startup.cs to… Read More »

Better text console for C#

I recently discovered how slow Console.MoveBufferArea actually is. I used it for writing NLog output to a console and discovered that at times of high output it became dead slow. I could at times see it flicker and update line for line while the whole machine temporarily came to a crawl. As I searched the… Read More »

HTML5: Drop-in prerender and prefetch script

Reading about prefetch and prerender, and especially Chromes prerender, got me thinking that this could to some extent be automated. My blog has become increasingly slow and I though that this would work as a simple quick-fix. This script relies on jQuery. Prefetch At startup (document ready) it will find any a-links tagged as “prefetch”… Read More »

Multiple deployment configs in one config file with ACL

Most projects that is deployed into production require some kind of config change upon deployment. Often it is the connection string that varies, but it can be any number of custom settings. Forgetting to change the config file when deploying, or forgetting to change config back on your dev machine after deploying can have disastrous… Read More »

Alternative directory layout for MVC

In .Net the MVC pattern is implemented through a template project. The project is set up for you when you create a new MVC application and imposes certain patterns on you. And that is exactly what MVC is, a pattern. By default you will create a controller, a view and a model. Usually you add… Read More »