AspNet routing problem with IIS7 and integrated pipeline

I have an asp.net site that uses asp.net routing to dynamically create some reports. I mapped the extension.zip to asp.net ISApi, then with routing I map url

1
2
 Using RouteTable.Routes.GetWriteLock()
            RouteTable.Routes.Add(New Route("reports/{reporttype}/{reportid}/report.zip", New MyReportRouter))

everything works perfectly, until I move this site to IIS7 and try to use it with integrated pipeline mode. When I browse to a valid report url I got this error.

image

It seems that my request must be satisfied by UrlRouting.axd handler… very strange. If I attach a debugger to worker process I can verify that routing is ok, my IRouteHandler is called correctly, it creates the handler that will be used to satisfy the request, but the handler was never called. After a deep search on the internet I did not find anything, except this link.

It seems that for a reason that I do not know, iis7 in integrated mode want to use UrlRouting.axd when routing is used, the solution is adding this line to the <handlers> section of config file

1
2
3
4
5
6
<add 
    name="UrlRoutingHandler" 
    preCondition="integratedMode" 
    verb="*" 
    path="UrlRouting.axd" 
    type="System.Web.HttpForbiddenHandler, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

The solution was to add an handler that maps, in integrated mode, the UrlRouting.axd to the HttpForbiddenHandler, now everything work perfectly.

Then I had another absurd problem when I moved everything on production server, the routing works, but it throws an exception my handler because httpContext.Current.Session is null. This is very strange, but even stranger is the solution, simply remove and readd session module in <Modules>

1
2
3
<modules>
    <remove name="Session" />
    <add name="Session" type="System.Web.SessionState.SessionStateModule"/>

This sounds absurd to me, but the real solution is another, putting  runAllManagedModulesForAllRequests into <modules> declaration.

1
<modules runAllManagedModulesForAllRequests="true">

You can check some other details here in ScottGu’s blog.

Alk.

Tags: Asp.Net Routing