Blog posts

  • Test the strength of your password

    December 10, 2014 | Tags: Off-topic

    Microsoft is offering a quite interesting service that tries to predict the next character in your password based on previous input. The area of what to consider as a strong or weak password borders to religion. But this service will at least give a hint of the strength/weakness in a password and might sometimes suprise you:

    Microsoft's Telepathwords password tester

    If you want to generate passwords you might check out this password generator from Norton.

  • Show text line breaks in ASP.NET MVC Razor view

    December 10, 2014 | Tags: CSS, ASP.NET, MVC, Snippet

    If you have a string with line breaks and want to show that text with the line-breaks intact in your Razor-based view, you can do this without replacing all \r\n with <br/>-tags. Instead present the text in an element that has the style property white-space set to pre-line. You should really add a class like:

    .line-breaks { white-space:pre-line; }

    <span class="line-breaks">@Model.MyText</span>

  • Offset a background image from the right or bottom using CSS

    December 10, 2014 | Tags: CSS, Snippet

    If you want to offset your background image a certain amount of pixels from the right with CSS you can do this by first defining it as right and then count away the pixels.

    Say that you wish the background image to start 20 pixels from the right you write your CSS as:

    .myclass {
      /* additional styles */
      background-position: right 20px top;

    This will align your background image to the top right and then offset it 20 pixels to the left. This can also be done as an offset from bottom.

    If you want you can also inline the position in the background tag directly. The following will align the background image 20 pixels from the right bottom corner:

    .myclass {
      /* additional styles */
      background: url("/images/my-image.png") no-repeat bottom 20px right 20px;

  • Entity Framework migration problem after merge

    December 10, 2014 | Tags: Troubleshooting, Entity Framework, C#

    A problem with code first migrations in Entity Framework arises when migrations in two branches are merged. Although you still have all the migrations in your merged project it still says "Unable to update database to match the current model because there are pending changes and automatic migration is disabled. Either write the pending model changes to a code-based migration or enable automatic migration. Set DbMigrationsConfiguration.AutomaticMigrationsEnabled to true to enable automatic migration."

    And if you create a new migration with the add-migration command you will end up with a migration that wants to add tables and/or fields that you already have in your database.

    Even if you do an update-database -targetmigration and try to re-run the migrations the error will remain.

    The cause of this problem is that each migration is created with a resource file (resx) that includes a snapshot of the database. This is what causes Entity Framework to be confused after the merge of two or more migrations.

    Solving the problem

    The fix is somewhat dirty but does the trick. You need to create a new migration that has the right snapshot but don't include the erroneous migrations.

    1. Add a new migration using add-migration
    2. Open the new migration and remove all the code from Up() and Down()
    3. Compile and run the project, it should be working again

    This empty migration will reset the snapshot and next time you change your data model the migrations will be created correctly.

    Be sure that you don't do any changes to your data model before you do this fix or otherwise make sure that you don't remove the valid migration steps.

  • HttpContext.Current not working in ASP.NET MVC

    December 09, 2014 | Tags: Troubleshooting, ASP.NET, MVC, C#

    This is most likely because it's no resolving to the correct class. Instead of using System.Web.HttpContext it tries to resolve towards System.Web.Mvc.Controller.HttpContext. The way to fix this is to prefix HttpContext.Current with System.Web so that your usage looks like: System.Web.HttpContext.Current