vb.netmefasp.net-mvc-5iroutehandler

MVC Custom RouteHandler not firing for files


I have the following code to register a route with my custom routehandler:

 routes.Add(New Route(path & "/{assembly}/{*resource}", New RouteValueDictionary(), New RouteValueDictionary(New With { _
             Key .assembly = AssemblyName _
            }), New EmbeddedContentRouteHandler(PluginAssembly, AssemblyName & "." & path)))

This allows me to access embedded resources in a compiled DLL for example: /Content/PluginAssemblyName/File.name

In MVC 3 and 4 the ProcessRequest function fires each time, but from MVC 5 it doesn't, it only fires when I specify a directory, which will obviously give me a null reference exception because I am looking for files, not directories (denominated, obviously, by . as a file should)

I've tried excluding .css and .js to try and see if my custom routehandler will fire, nothing. Testing this in the MVC 4 project, works perfectly.

Starting to tear my hair out.

Any ideas why the RouteHandler won't fire in MVC 5, but does in MVC 4 and 3?

(This is a Pluggable MVC project using MEF that I've brought to MVC 5 piece by piece since the upgrade path didn't pan out too well)


Solution

  • Starting ASP.net 4, it will not intercept URLs that end with an extension. Follow the solution here to revert to the old behaviour.

    and don't forgot to add this line in your route configuration if you want to intercept existing files.

    routes.RouteExistingFiles = true;