In the summer I gave up trying to make my web server (on the internal Microsoft network) look perfect – and really I gave up on HTML and the complexity that went with it.

What I wanted was simple text formatting that didn’t require specialized tools and coincidentally I discovered Markdown: http://en.wikipedia.org/wiki/Markdown

And what I saw was a simple format – one mostly used for user input for forms. What I needed was something to help me in the role of an author of content.

Of course, it’s not as if one can create a text file called “default.markdown” and place it in your web server and have it all “Just Work” – have IIS read the markdown file and emit something browsers can display – HTML.

Or maybe this is possible ….

Presenting an IIS7 Handler for Markdown content

After installing the handler (simple), just create files in your web site with “.markdown” as the extension and IIS will translate it to HTML for browsers on-the-fly.

The heavy lifting was done for me when I found this library: http://www.brianjeremy.com/2007/12/07/revisied-markdownnet-library/

I freshened up the code with some .NET 3.5 goodness and generics and implemented a simple IIS7 handler that hooks it to IIS. The rest was just to add a bit of extra HTML to the output to handle document titles and refer to a stylesheet.

 

Source and Binaries

Available Here: http://sdrv.ms/1bgqyjO

 

 

Installing the Handler

Before you install the handler, you’ll see that the server in this example us serving HTML content from Default.htm

image

Download the ZIP file with the source code.

Open the MarkdownHandler solution with Visual Studio 2008

Compile the solution

in solution there’s a project called MarkdownHandler and inside it you’ll find two binaries are produced (Markdown.NET.dll and MarkdownHandler.dll)

image

Now start the IIS7 Management Console

image

Navigate to the Default Web Site

image

Right click on the Default Web Site and select Explore

image 

And Explorer window will open to the location of the rot folder for this web site

image

This DLLs need to go into the bin directory. So, right click on the bin directory and select Open

image

image

Now copy those DLLs to this folder

image

And close the Explorer window

Navigate back to the Default Web Site

image

Right click on Handler Mappings and select Open Feature

image

You will see that there is no Markdown handler in the list. We will add one now.

In the Actions pane, Select Add Managed Handler

image

The Add Managed Handler dialog opens

image

For Request path enter “*.markdown”

Then for Type click the arrow to see the choices

image

image

“MarkdownHandler.MarkdownHandler” is listed because it is in the bin directory.

Select “MarkdownHandler.MarkdownHandler” .

For Name enter “Markdown”

image

Click on the Request Restrictions button

image

The Request Restrictions dialog launches

image

In the Mapping tab, click Invoke handle only if request is mapped to

Select File

image

For the Verbs tab – leave this one alone

image

On the Access tab you can leave it set to Script

image

Click OK to dismiss the dialog

image

Click OK to dismiss the dialog

image

Now in Handler Mappings you will see that the Markdown handler is enabled.

image

Now create a Default.markdown text file the root of your site

image

Mine looks something like this

image

And launch that page and you will see

image

image

And if you want you can change the default document to look for markdown files automatically …

image

image

image

image

image

So now I can just browse to the server and the default markdown is shown automatically

image

image

 

FINAL THOUGHTS AND COMMENTS

  • I’ve been running with markdown as my default homepage for about 5 months now – seems stable but keep in mind my server is not under heavy load
  • I hope this inspires you to do some creating things with the IIS web handlers
  • It might be fun to implement a custom language for pages using Oslo