Monorail RC 2.1 routing thinks that a missing static file (like a .jpg) is an controller/action

StackOverflow https://stackoverflow.com/questions/12313773

Question

I've started learning (and using) Monorail a little while ago, and recently, I've dabbled into routing. Unfortunately, the documentation around it is kinda sparse, but I've managed to get some info from various blog posts, most of them 2 years + old. I managed to setup the routing pretty quickly, BUT I realized that Monorail's routing engine confuses .jpeg files as controller/action requests WHEN they are not found.

The webconfig file is pretty standard:

 <monorail useWindsorIntegration="false" defaultUrlExtension=".rails">
    <url useExtensions="true"/>
    <controllers>
      <assembly>NetTwitter.Web</assembly>
    </controllers>
    <viewcomponents>
      <assembly>NetTwitter.Web</assembly>
    </viewcomponents>
    <viewEngine viewPathRoot="Views" customEngine="Castle.MonoRail.Framework.Views.NVelocity.NVelocityViewEngine, Castle.MonoRail.Framework.Views.NVelocity"/>
  </monorail>
 <system.web>
    <httpHandlers>
     <!-- block direct user access to template files -->
      <add verb="*" path="*.vm" type="System.Web.HttpForbiddenHandler"/>
      <add verb="*" path="*.boo" type="System.Web.HttpForbiddenHandler"/>
      <add verb="*" path="*.st" type="System.Web.HttpForbiddenHandler"/>
      <add verb="GET" path="*.css" type="System.Web.StaticFileHandler" />
      <add verb="GET" path="*.js" type="System.Web.StaticFileHandler" />
      <add verb="GET" path="*.jpg" type="System.Web.StaticFileHandler" />
      <add verb="GET" path="*.gif" type="System.Web.StaticFileHandler" />
      <add verb="GET" path="*.png" type="System.Web.StaticFileHandler" />
      <add verb="GET" path="*.jpeg" type="System.Web.StaticFileHandler" />
      <add verb="*" path="*.rails" type="Castle.MonoRail.Framework.MonoRailHttpHandlerFactory, Castle.MonoRail.Framework"/>
    </httpHandlers>
    <httpModules>
      <add name="routing" type="Castle.MonoRail.Framework.Routing.RoutingModuleEx, Castle.MonoRail.Framework" />
    </httpModules>

As is the initialization of the routing engine inside the Global.asax:

 public void Application_OnStart()
        {
            log4net.Config.XmlConfigurator.Configure();
            RoutingModuleEx.Engine.Add(
                new PatternRoute("<controller>/[action]"));
        }

The error itself says it pretty clearly:

{"Controller not found. Area: '' Controller Name: 'content'"}

So, what can I do? Thanks in advance.

Était-ce utile?

La solution

This is because you are using the RoutingModuleEx. That will rewrite the URL before the actual httpHandlers are matched against.

And your route is to general for this, probably.

We solve it by having a /static/ folder which has it's own web.config, therefore overriding the original web.config.

This one contians only:

<system.webServer>
    <handlers>
        <clear/>
        <add name="StaticFile" path="*" verb="*" modules="StaticFileModule" resourceType="Either" requireAccess="Read" />
    </handlers>
</system.webServer>

You might want to remove the rounting module from here as well, since it might be inherited. We have however not noticed any issue with it, but haven't really put my head in it either. It might be that we don't match any routes when we are one level down, or subfolders doesn't inherit httpModules.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top