Stack Overflow reference questions

In this post I keep a list of questions and answers I frequently link to on Stack Overflow.



What is a NullReferenceException and how do I fix it?

HTTP 500 – Internal Server Error on IIS

How to find the underlying cause for an HTTP 500 – Internal server error in IIS?

Localization of ASP.NET MVC Unobtrusive Validation

MVC 3 jQuery Validation/globalizing of number/decimal field

Change Visual Studio New Class Template

How do I edit the Visual Studio templates for new C# class/interface?

IPC mechanisms in .NET

IPC Mechanisms in .NET – Usage and Best Practices

Enable WCF Tracing

How to turn on WCF tracing?



Enable Error Reporting in PHP

How to get useful error messages in PHP?

Posted in Tech | Leave a comment

Posting sortable form items to an MVC controller

I wanted to allow the user to edit a list of items while also enabling the user to sort them, and to post that back in a meaningful way without parsing on the server side. This does the trick:

public class SortableModel
  public List<CustomItem> CustomItems { get; set; }

public class CustomItem
  public int Order { get; set; }
  public string Description { get; set; }

var model = new SortableModel
  CustomItems = new List<CustomItem>
    new CustomItem { Order = 0, Description = "Test 1"},
    new CustomItem { Order = 1, Description = "Foo 2"},
    new CustomItem { Order = 2, Description = "Bar 3"}


<script src="@Url.Content("Scripts/jquery-1.9.1.js")"></script>
<script src="@Url.Content("Scripts/jquery-ui-1.10.1.js")"></script>
<script type="text/javascript">
  $(function () {
      stop: function (event, ui) {

        $("#sortMe li").each(function (index, element) {
          // find the hidden input in each <li> and set it to its current index, according to the DOM
          var hiddenInput = $(element).children(".order").first();
@using (Html.BeginForm())
  <ul id="sortMe">
  @for (int i = 0; i < Model.CustomItems.Count; i++)
    <li>@Html.HiddenFor(m => m.CustomItems[i].Order, new { @class = "order" }) @Html.TextBoxFor(m => m.CustomItems[i].Description) <span>Drag me!</span></li>
  <input type="submit" value="Save" />

Now my action can accept a SortableModel parameter, where we can loop through the list of CustomItems in order to determine their order!

public ActionResult CustomFieldsForPort(SortableModel model)
  // do your thing with model!
  return View(model);

Up next: adding and deleting items.

Posted in Tech | Leave a comment

Controller injection with Unity under ASP.NET MVC 4

A lot of different manuals exist on the web explaining various portions of MVC unit testing, Entity Framework mocking and Inversion of Control (IoC) using Unity as dependency injection container. In this and hopefully future posts I’ll try to sew together the bits I found on various places.
Continue reading

Posted in Tech | Tagged , , , , , | 1 Comment

An idea for multilingual webpages: the Content-Languages response header

Much content on the web is provided in multiple languages. Think about corporate websites, Wikipedia and various sites running on popular content management systems. The issue I would like to address is the display and selection of the languages the content is available in.
Continue reading

Posted in Tech | Leave a comment

Using the WebClient class – with cookies!

Contrary to the somewhat crude HttpWebRequest class, the WebClient allows the developer to easily download and upload data and strings from and to webservers.

The rough edges of the HttpWebRequest class make developers jump to the WebClient (or HttpClient, since .NET 4.5) to significantly increase the ease-of-use. The WebClient has one drawback: it doesn’t support cookies!

Continue reading

Posted in Tech | Tagged , , , , | Leave a comment

Configuring a shared packages directory for NuGet and automatically downloading packages

This entry is also available in Dutch.

The ever so popular Visual Studio extension named NuGet enables the developer to easily install packages from within the development environment. NuGet packages contain populair and less known libraries, like log4net, jQuery and Entity Framework.

Continue reading

Posted in Tech | Tagged , , , | 2 Comments

Sockets and protocols: exchanging messages. Using bytes.

There’s also a Dutch version of this article available.

When two applications wish to communicate over an (inter)network, sockets quickly come into play. Nowadays sockets are delivered by almost every operating system, in the form of an API that enables the developer to easily transfer data through a local network or over the internet to another machine.

Continue reading

Posted in Tech | Tagged , , | 4 Comments

Remove Origin advertisements

Do you love the Sims and FIFA advertisements popping up after logging in to Origin when you’re about to play some Battlefield 3? Or even the Premium ads while you already have bought Premium? I don’t, so inspired by this post I contacted EA support and asked if there’s any way to disable displaying the advertisements. Their solution: reboot your PC. Luckily, I found a real solution:

Run Notepad (or the slightly better alternative) and open the file %appdata%\Origin\Settings.xml, and locate the following lines:

<Setting key="PromoBrowserGameFinishedLastShown" type="2" value="xxx"/>
<Setting key="PromoBrowserOriginStartedLastShown" type="2" value="xxx"/>

Change the values of xxx to 9999999 and the ads will disappear. :)

Posted in Tech | Tagged , , | 4 Comments

Remotely viewing detailed error pages in IIS

When deploying applications or services to IIS one can sometimes run into errors that haven’t been foreseen during development. Of course, with appropriate logging you can quickly identify the source of the problem, but when your site lacks this functionality you’d love to see the same detailed exception information as you see while you’re developing the application.

Continue reading

Posted in Tech | Tagged , , | Leave a comment

This is a blog

Hello and welcome to my new blog!

I’ve been blogging in Dutch for a few years now, and I wanted to try something new: I’m going to write small posts about pieces of code, configuration or software that I find useful when developing. When I’ve got some time to spend, I’ll translate my existing Dutch tech blogs into English, so the whole world can read them. It’s up to you to decide whether that’s a good thing.

Stay tuned, updates will follow soon.

Posted in Tech | Leave a comment