Tahir Hassan's Blog

My Technical Notes

Tuesday, 2 September 2014

Accessing Visual Studio 2013 Web Server (IISExpress) remotely

Visual Studio 2013 now uses IISExpress when it hosts web applications which are being debugged.

Here are the instructions from Giles Middleton's guide, which I have made minor changes. Following are the steps to apply, with your computer name replacing `comp_name` and your Visual Studio port number to replace `49845`.

1. Run the following command (in cmd.exe) as Administrator:

2. Open up `My Documents\IISExpress\config\applicationhost.config`. This file contains the host headers for all your projects. For your specific project, copy the binding element and paste it underneath it with the `localhost` replaced with `comp_name`. So from: to:

Now you should be able to use `http://comp_name:49845` remotely (after restarting IISExpress).

3. One final step is to remove the `urlacl` when we are done:

4. Lastly, for the sake of completeness, I have included the instructions on opening the port `49845` in the Windows Firewall (which I did not have to do, because I don't use it):

  • Go to the Windows Firewall with Advanced Security panel
  • Create a new inbound rule.
  • Click ‘Port’.
  • Click ‘Next’.
  • Click TCP.
  • Enter a specific port `49845`.
  • Click ‘Next’.
  • Click ‘Allow the connection’.
  • Click ‘Next’.
  • Click ‘Next’ (you could untick Public).
  • Give it a name `My Web App` and press Finish.

Thursday, 28 August 2014

Upload/Send File to User's Browser

The following method `SendFile` will send a file to the user's browser:

Tuesday, 19 August 2014

The "Null" monad in F#

In F#, we can use computation expressions to implement monads. Here is a definition of null' which is our monad:

Given a C# class definition of Student below, which contains an instance of Course which in turn has a property CourseId: string:

Here is how we would safely extract the CourseId from a given student:

Ignoring Visual Studio Packages within SVN Directory.

Nuget advices that the svn:ignore pattern for the packages directory should be:

That pattern is supposed to stop any file/folders with names which don't end in .config, but unfortunately allows names which are five or less characters in length. It also allows any file name where the sixth last character is c, or the fifth last character is o or ... the last character is g.

To get around this, we first need to outlaw any names which are six or less characters in length, and we need to outlaw any name which does not end specifically in config. The way we do this is by ensuring that the seventh last character is not a dot or the sixth last character is not a c or the fifth last character is not a o or ... or the last character is not a g.

Here is how it looks:

I have written a short F# script which generates this for a given file extension:

Calling allowExtensionOnly "config" will produce the above list.

Wednesday, 13 August 2014

ASP.NET: Getting File System Path and Resolving Virtual Paths

To get the directory of the base directory, we can call:

This is equivalent to:

To resolve a virtual path to an http path that the client can use, we do:

Monday, 11 August 2014

SQL Server: Getting First Word of a String

Below if a function which returns us the first word of a string (i.e. part of the string before a space character):

And we use it like so:

F#: Pattern matching on the Type of Input

Pattern matching based on the type of the input is readily done easily using a syntax called "Active Patterns". First we define our active pattern As:

Thereafter, to use it is results in very natural code:

Here is some code to test the above code:

I first posted this solution on StackOverflow.com.