If you've recently tried to install the latest version of BlogEngine.NET on Mono, you would have noticed that the URL rewriting does not work for posts, but does work for categories.

This comes down to a bit of an oddity in the mono ASP.NET runtime. It turns out that if you have a path like /posts/2009/03/09/slug.aspx and an actual file called /posts.aspx exists in the root site, mono gets confused and mangles the path.

In your URL rewriting IHttpHandler you'd expect the path returned by context.Request.Path to match what was requested, but in reality Mono will give you /posts.aspx.cs/2009/03/09/slug.aspx instead. This is obviously a bug in Mono, but it's fairly easy to work around.

To fix the issue in BlogEngine.NET, open UrlRewrite.cs in BlogEngine.Core and modify your context_BeginRequest method to look like this:

private void context_BeginRequest(object sender, EventArgs e) {
    HttpContext context = ((HttpApplication)sender).Context;
    string path = context.Request.Path.ToUpperInvariant();
    string url = context.Request.RawUrl.ToUpperInvariant();
    // fixes an oddity in mono where .aspx.cs is added
    path = path.Replace(".ASPX.CS", "");
    url = url.Replace(".ASPX.CS", "");

Compile and deploy!

I am a software developer / architect currently interested in combining .NET technologies with open-source operating systems. 

I am a member of the open-source BlogEngine.NET development team and focus mainly on ensuring Mono compatibility for the project.



At StayUnlimited Cape Town accommodation we help you choose from and book guest houses, self catering apartments, bed & breakfasts, luxury villas and hotel accommodation.