MonoRail Tab Routing Using IIS 7?

I am trying to get the routing module to work with the default action or controller, but it does not. I always come across a 404 page that is not found. Did I forget to do something? I really like routing in an ASP.NET MVC function, but I'm not sure I can do the same in MR. I am using IIS7 with a lock assembly for .NET 3.5.

+6
c # model-view-controller asp.net-mvc castle-monorail
source share
3 answers

If you are using IIS7, you need to register the routing module in the system.webServer / httpModules node file.

System.web / httpHandlers and httpModules are not considered AFAIK IIS7.

MonoRail routing definitely works; we work happily. Here are the config and global.asax.cs snippets:

<system.web> <authentication mode="None" /> <compilation debug="true" /> <!-- IIS6 / integrated dev server handler/module config --> <httpHandlers> <clear /> <add path="favicon.ico" verb="*" type="System.Web.StaticFileHandler"/> <add path="Trace.axd" verb="*" type="System.Web.Handlers.TraceHandler"/> <add path="*.config" verb="*" type="System.Web.HttpForbiddenHandler" /> <add path="*.spark" verb="*" type="System.Web.HttpForbiddenHandler" /> <add path="*.sparkjs" verb="*" type="System.Web.HttpForbiddenHandler" /> <add path="/content/**/*.*" verb="*" type="System.Web.StaticFileHandler" /> <add path="/content/**/**/*.*" verb="*" type="System.Web.StaticFileHandler" /> <add path="/content/**/**/**/*.*" verb="*" type="System.Web.StaticFileHandler" /> <add path="/content/**/**/**/**/*.*" verb="*" type="System.Web.StaticFileHandler" /> <add path="*" verb="*" type="Castle.MonoRail.Framework.MonoRailHttpHandlerFactory, Castle.MonoRail.Framework" /> <add verb="*" path="*.castle" type="Castle.MonoRail.Framework.MonoRailHttpHandlerFactory, Castle.MonoRail.Framework"/> </httpHandlers> <httpModules> <add name="routing" type="Castle.MonoRail.Framework.Routing.RoutingModuleEx, Castle.MonoRail.Framework" /> <add name="PerRequestLifestyle" type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.MicroKernel" /> </httpModules> <trace enabled="true"/> </system.web> <!-- IIS 7 handler/module config --> <system.webServer> <handlers> <clear /> <add name="FavIcon" path="favicon.ico" verb="*" type="System.Web.StaticFileHandler"/> <add name="Trace" path="Trace.axd" verb="*" preCondition="integratedMode" type="System.Web.Handlers.TraceHandler"/> <add name="BlockConfig" path="*.config" verb="*" preCondition="integratedMode" type="System.Web.HttpForbiddenHandler" /> <add name="BlockSpark" path="*.spark" verb="*" preCondition="integratedMode" type="System.Web.HttpForbiddenHandler" /> <add name="BlockSparkJs" path="*.sparkjs" verb="*" preCondition="integratedMode" type="System.Web.HttpForbiddenHandler" /> <add name="content" path="/content/**/*.*" verb="*" preCondition="integratedMode" type="System.Web.StaticFileHandler" /> <add name="content2" path="/content/**/**/*.*" verb="*" preCondition="integratedMode" type="System.Web.StaticFileHandler" /> <add name="content3" path="/content/**/**/**/*.*" verb="*" preCondition="integratedMode" type="System.Web.StaticFileHandler" /> <add name="content4" path="/content/**/**/**/**/*.*" verb="*" preCondition="integratedMode" type="System.Web.StaticFileHandler" /> <add name="castle" path="*" verb="*" type="Castle.MonoRail.Framework.MonoRailHttpHandlerFactory, Castle.MonoRail.Framework" modules="ManagedPipelineHandler" scriptProcessor="" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv2.0" /> </handlers> <modules> <add name="routing" type="Castle.MonoRail.Framework.Routing.RoutingModuleEx, Castle.MonoRail.Framework" /> <add name="PerRequestLifestyle" type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.MicroKernel" /> </modules> <validation validateIntegratedModeConfiguration="false" /> </system.webServer> 

(Actually, we never worked on IIS6, but did it on the web-dev server - we have support since then, and I was told that it will work with * IIS6-level mapping with aspnet_isapi.dll - but to by that time, dev working with Win2003 was updated to something with IIS7 on it, so we did not try this)

  protected virtual void RegisterRoutes(IRoutingRuleContainer engine) { engine.Add ( new PatternRoute(ThorController.CtlrHome, "/[controller]") .DefaultForController().Is(ThorController.CtlrHome) .DefaultForArea().Is(ThorController.AreaPublic) .DefaultForAction().Is(ThorController.ActionIndex) ); engine.Add ( new PatternRoute(ThorController.KeyDefault, "/<area>/<controller>/[action]/[id]") .DefaultForArea().Is(ThorController.AreaPublic) .DefaultForAction().Is(ThorController.ActionIndex) .DefaultFor(ThorController.KeyId).IsEmpty ); } 

(the first route processes our application root)

(consts on our base class ThorController try to shorten string literals)

As an aside, does anyone know if there is a syntax for doing what we do with static file processing on a single line? Of course, you need to be better than our "decision"; -)

+5
source share

How do you configure routing? I had problems trying to manage the routing rules from web.config, but switching to inline code on the start application worked for me.

I tried to find the answer to the question why the xml path did not work, but did not find it. They made a big redistribution of the routing engine with RC3, which could break it.

Example from Application_OnStart ()

 var rule = new PatternRoute ("default", "/")
     .DefaultForController (). Is ()
     .DefaultForAction (). Is ("index");

 RoutingModuleEx.Engine.Add (rule);

Remember to load the RoutingEngineModule module before MonoRailHandler in web.config.

+1
source share

I already tried to register routing, but this still does not work.

Here is my configuration file:

 <system.web> <httpHandlers> <add verb="*" path="*.rail" type="Castle.MonoRail.Framework.MonoRailHttpHandlerFactory, Castle.MonoRail.Framework" /> <add verb="*" path="*.vm" type="System.Web.HttpForbiddenHandler" /> <add verb="*" path="*.boo" type="System.Web.HttpForbiddenHandler" /> <add verb="*" path="*.st" type="System.Web.HttpForbiddenHandler" /> </httpHandlers> <httpModules> <add name="routing" type="Castle.MonoRail.Framework.Routing.RoutingModuleEx, Castle.MonoRail.Framework" /> </httpModules></system.web> <system.webServer> <handlers> <add name="MR" path="*.rail" verb="*" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" preCondition="classicMode,runtimeVersionv2.0,bitness32" /> </handlers> </system.webServer> 
0
source share

All Articles