Tahir Hassan's Blog

My Technical Notes

Wednesday, 15 October 2014

CSS clearfix AKA group aka whole class

If you wish to have a "container" css class which contains all of its children, then you are searching for the CSS clearfix hack.
If you had a left-floated div `l` and a right-floated div `r` in a container, but you wanted everything underneath it to not to go left or right of either `l` or `r`, then you want a special container css class which stops this. with the `whole` class not defined, it looks like so:
RED
YELLOW
WHAT FOLLOWS
If we wanted the `what-follows` div to be underneath the floated divs, then we would define the `whole` class as follows: With this CSS class defined, the `whole` div will act like a "whole":
RED
YELLOW
WHAT FOLLOWS

Thursday, 2 October 2014

Error message 401.2.: Unauthorized: Logon failed due to server configuration

If you are using Windows authentication within your `web.config`:

then you must also enable Windows Authentication within the project properties. Strangely enough there are two windows for this. The first one is when you right click the Project and go to `Properties` (or `Alt-Enter`):

The other one is the `Properties Window` which can be opened by clicking on `VIEW` → `Properties Window` or alternatively press `F4`. Here is how that looks:

Change `Windows Authentication` to `Enabled`.

This blog post was based on Saravanan's blog post.

Tuesday, 30 September 2014

Ignoring WCF *.svc files in ASP.NET routing

While writing a WCF .svc service in ASP.NET, I kept getting the 404 error: `The resource cannot be found.`

I spent ages Google-ing for the answer, which turned out to be quite simple: ignore requests containing `.svc` and the problem will go away. Add the following line to `RouteConfig.RegisterRoutes` method:

Note that the inspiration comes from Phil Haacks website.

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.