Windows Authentication in IIS Express with Visual Studio 2015

When freshly installing Visual Studio and using windows authentication, you typically run into the “The requested page cannot be accessed because the related configuration data for the page is invalid” error.

Before, you would go to c:\users\[yourusername]\documents\IISExpress\config\applicationhost.config and change the following section


<section name="windowsAuthentication" overrideModeDefault="Deny" />

<section name="anonymousAuthentication" overrideModeDefault="Deny" />
<add name="WindowsAuthenticationModule" lockItem="true" />
<add name="AnonymousAuthenticationModule" lockItem="true" />


to look like this

<section name="windowsAuthentication" overrideModeDefault="Allow" />

<section name="anonymousAuthentication" overrideModeDefault="Allow" />
<add name="WindowsAuthenticationModule" lockItem="false" />
<add name="AnonymousAuthenticationModule" lockItem="false" />


Only, with Visual Studio 2015, this does not seem to work anymore. The settings file being used by IISExpress is now localized in C:\path\to\your\solution\.vs\applicationhost.config. Change this file like above, restart your project and IIS Express and you should be back on track again!

Alternatively, you can add


to your .csproj file. This way, the applicationhost.config in your documents folder will be used again.

Spell checking git commit messages in vim

If you want to enable spell checking when you are writing a commit message, you can add

set spell spelllang=en_us

to your .vimrc file. This file is located in your home folder, so e.g. C:\Users\itto\.vimrc.

Errors will be highlighted with a red background. Nice and easy.

Drush: “Command pm-enable needs a higher bootstrap level to run”

When running drush you can run into this error message. In my case, the mysql command line tool provided with Mamp Pro was not available. You can easily test this by typing the command ‘mysql’ in terminal. Your output might be -bash: mysql: command not found.

To solve this, do the following in terminal:
sudo vim ~/.bash_profile
Press i
Move to the last line and append
export PATH=/Applications/MAMP/Library/bin/:$PATH
Hit escape
Type in :wq (including the colon) to write the file and quit vim.
Reload your profile by running source ~/.bash_profile.

The mysql command AND drush should now work!

Restore a SQL Server database with C#

private void RestoreDatabase(String databaseName, String backUpFile, String serverName)
	var connection = new ServerConnection(serverName);
	var sqlServer = new Server(connection);
	var restore = new Restore();

	string pathBackupfile = Path.GetDirectoryName(backUpFile);

	if (pathBackupfile != null) {
		string logFile = Path.Combine(pathBackupfile, databaseName + "_Log.ldf");
		string dataFile = Path.Combine(pathBackupfile, databaseName + ".mdf");

		restore.Action = RestoreActionType.Database;
		restore.Database = databaseName;
		var bkpDevice = new BackupDeviceItem(backUpFile, DeviceType.File);
		restore.ReplaceDatabase = true;

		//Relocate mdf & ldf files
		System.Data.DataTable logicalRestoreFiles = restore.ReadFileList(sqlServer);
		restore.RelocateFiles.Add(new RelocateFile(logicalRestoreFiles.Rows[0][0].ToString(), dataFile));
		restore.RelocateFiles.Add(new RelocateFile(logicalRestoreFiles.Rows[1][0].ToString(), logFile));


Embed images in a mail message using C#

I was recently writing a webapplication for one of our clients. The application is a training management tool and thus involves sending loads of e-mail. This way people get reminded that they’ll be following a training in the next days or asked to write a review about their training. To make the mail look great, we wanted it to be in HTML and contain the company logo.

A first attempt was made by just writing the html for the mail and use an ordinary image-tag with a reference to the client’s intranet (like this: <img src=””/>). However, the kick-ass intranet-security of our client wouldn’t allow this and each time the mail was opened, the user was prompted for his credentials. Very annoying! So we had to include the image in the mail as an attachment. You see it every day, but apparently the code to do this in c# isn’t that widely spread. So here’s my function to accomplish it:

/// <summary>
/// Embeds the company logo into the given mail message
/// </summary>
/// <param name="message">Message in which the logo should be embedded</param>
private static void EmbedCompanyLogo(MailMessage message)
   AlternateView av1 = AlternateView.CreateAlternateViewFromString(message.Body, null, System.Net.Mime.MediaTypeNames.Text.Html);
   string strImageUrl = System.Web.HttpContext.Current.Server.MapPath("~/images/logo_print.gif");
   LinkedResource logo = new LinkedResource(strImageUrl, System.Net.Mime.MediaTypeNames.Image.Jpeg);
   logo.ContentId = "companylogo"; 
   //To refer to this image in the html body, use <img src="cid:companylogo"/>

As mentioned in the code comment, in your mail message you can refer to the image with a source equal to “cid:companylogo”.

If you have any thoughts, remarks or questions, the comments are open…

Downloading Office 2007 documents from IIS 6

Today at work, I had to make a small form that enables the user to apply for a job and upload their resume. In the backoffice that I made, the admin has the possibility to view all applicants and download the files they’ve uploaded. Possible file types are .pdf, .doc and .docx. While testing this application, I had uploaded a Word file and checked via FTP that the upload including the renaming of the file and moving it to the correct folder went fine. So, as a final test, I tried to download the uploaded file via my browser, just like the admin would do when te application went live. This didn’t work at all! The server just returned a 404 Not Found error page. I tried for maybe half an hour and started to think I was going crazy. I could see the file through FTP, but could not download it. How is that possible!?

Then, after half an hour, I did what I should have done all along. I renamed the file from the Microsoft Word 2007 file extension .docx to a regular .doc and it worked instantly! After a few seconds looking in Google, I realized that IIS6.0 (which runs on our hosting provider’s server) is Secure By Design. This means that MIME types are in a white list. Everything that isn’t known to the server is hidden by default and thus returns a 404 error.

To solve this problem, you have to add a MIME type to IIS. To do this, you just follow these simple steps:

  • In the Internet Management console, you go to the properties of the web site, by right clicking onto it.
  • Under “HTTP Headers”, “Mime Types”, you add a new extension (without the leading dot) with the mime type “application/vnd.openxmlformats-officedocument.wordprocessingml.document”.

You can find a complete list of mime types for office 2007 documents on the Microsoft website.