I often map HTML extension to the ASP.NET DLL in order to use URL rewriter with .html extensions. In a recent project, we renamed all URLs to end with .html. This works great, but failed when we used FCK Editor. Static HTML files would not get served because we mapped the HTML extension to the .NET Framework. We can use .html extension with our rewriter but still want to use IIS behavior with static HTML files.
I thought that this could be resolved with a simple HTTP handler. We would map URLs of static files in our rewriter to this handler that would read the static file and serve it, just as IIS would do.
This is how I coded the class. Note that this may not be bullet proof. I only tested it once and I am sure that the logic behind IIS is more complicated that this. If you find errors or think of possible improvements, let me know.
Public Class ISAPIDotNetHandler
Sub ProcessRequest(ByVal context As HttpContext) _
context.Response.ContentType = "text/html"
Dim uri As String = context.Request("fileUri")
If String.IsNullOrEmpty(uri) Then
Throw New ApplicationException("No fileUri")
If Not uri.ToLower.EndsWith(".html") Then
Throw New ApplicationException("Extension not allowed")
Dim fullPath As String = context.Server.MapPath(uri)
Dim stream As IO.StreamReader = _
stream = Nothing
Catch ex As Exception
context.Response.StatusCode = 404
ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
As you see, with our static files mapping to this handler using query string (e.g.: /ISAPIDotNetHandler.ashx?fileUri=index.html) you will have the same behavior as if you ask for the URL/index.html.
Finally, test this only in IIS with the HTML extension map to aspnet_isapi.dll. URL rewriting will work in Casini (Internal Web Server shipped with Visual Studio) but it's not the same as with IIS since EVERY request is handled by .NET.
Published: 4/19/2009 11:25 PM
I am the general director of Nitriques Solutions inc. We build software and web solutions for enterprises using .NET 2.0 and 3.5, MS-SQL Server 2005 running on various Server 2003.
We offer a variety of products, from simple corporate web site with CMS to complete integration of intranets.
I have been working with asp et MS-SQL since 2002. I am particularly interested in web development 2.0, ajax, css, xhtml, asp.net, jQuery, Open Social and other web technologies.
In my spare time (when this concept exist in my life), i like to snowboard, skydive or free fall in wind tunnels and learning cool new stuff about anything.
Please feel free to contact me. http://www.nitriques.com