Nancy + Static Content + OWIN + SystemWeb
Originally published on my old blog at cumps.be on January 6, 2014.
I’ve just started working with Nancy to create a new site. It’s going to be hosted on IIS and I decided to try and take the OWIN approach. When I got to the part of managing static content I ran into some problems, mainly not getting it to work. Read on for the solution!
The Problem
My site uses some CSS and Javascript files, and likes to resolve it to /js and /css. According to the wiki, this should be simple enough, stick them into /Content and map them. In my Bootstrapper, I have the following:
protected override void ConfigureConventions(NancyConventions conventions)
{
base.ConfigureConventions(conventions);
conventions.StaticContentsConventions.Add(StaticContentConventionBuilder.AddDirectory("/css", @"/Content/Styles"));
conventions.StaticContentsConventions.Add(StaticContentConventionBuilder.AddDirectory("/js", @"/Content/Scripts"));
}
Reload and … nothing! Upon further inspection, I saw my requests for files in /js returned a 404 instead of the file.
The Solution
As it turns out, when you use Microsoft.Owin.Host.SystemWeb, you need some additional configuration to get static content working.
Inside your OWIN Startup.cs, you need:
using Microsoft.Owin.Extensions;
using Owin;
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.UseNancy();
app.UseStageMarker(PipelineStage.MapHandler);
}
}
And inside your Web.config you need to have:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
With those two changes, static content is being served correctly.
You May Also Like
GPG in Outlook 2007 - OutlookGnuPG
A long time ago, I used PGP for signing my email, but I stopped using it. Probably because I didn't quite get the concept yet, but that has changed now. Today I switched to GPG for signing my mail and files, with all the required files running from my memory stick. One thing bothered me however, no Outlook 2007 support at all. There are some plugins around for older Outlook versions, but that didn't quite work out. So I decided to develop my own! And after a few weeks of development and testing, it's done and ready to be set free upon the world.
Modified MVC AccountController for Preview 5
I just downloaded the ASP.NET MVC Preview 5 bits from Codeplex and started on my first experiment.
C# World Of Warcraft Armory Library 0.1
Since I started playing World of Warcraft again, I've taken a bit more of a developer approach to it this time, and after founding a little casual guild, I decided to create a site for it. Also because I'm quite geeky when it comes to statistics, and a bit of a theory crafter, I planned to populate our guild site with lots of stats.



