Hi,
This is the one i use (worked on mono 2.2 and 2.4) i also extended the
DefaultUrlBuilder because i wasn't able to correctly use the UrlHelper with
the route param, however i don't remember exactly which changes i did.
If you have problems with this send me an e-mail, i will help you if i have
time.
Did you routes work on windows? which mono version are you using?
Best Regards,
Ricardo Lopes.
2009/4/30 carolina w <[email protected]>
> Hi,
>
> I removed the "~" symbol from the returned value of
> CreateMonoRailPath(RouteMatch), like you suggested in the past thread.
> Unfortunately, I still do not get the application routing to work on mono +
> Linux.
>
> Now I get resource not found exceptions for rules like this
> (with the routing rules like <community>/<controller>/<action>) and for the
> others that previously worked without the class changes.
>
> I get the error:
> **
> *The resource cannot be found*
>
> *Description: *HTTP 404. The resource you are looking for (or one of its
> dependencies) could have been removed, had its name changed, or is
> temporarily unavailable. Please review the following URL and make sure that
> it is spelled correctly.
>
> *Resource URL: */home/index.rails
> It would be nice If you could send me the files with the changes.
>
> Thanks
>
> On Tue, Apr 28, 2009 at 10:45 PM, Ricardo Lopes <[email protected]> wrote:
>
>>
>> Hi,
>>
>> I had the same problem some time ago.
>>
>> I was able to fix the problems I had on mono with just a small changes
>> to the castle code (RoutingModuleEx and DefaultUrlBuilder).
>>
>> See:
>>
>>
>> http://groups.google.com/group/castle-project-devel/browse_thread/thread/dd3dcba67b0a4e26/a7776c77d0824e66?hl=en&lnk=gst#a7776c77d0824e66
>>
>> The changes were only 2 or 3 lines and the changed classes works on
>> m...@linux and ....@windows.
>>
>> If you want I can send the files (I could swear that i uploaded them
>> to donjon but I couldn't find them, I will check this later...)
>>
>> Best Regards,
>> Ricardo Lopes.
>>
>> 2009/4/28 heike <[email protected]>:
>> >
>> > Hi,
>> >
>> > I am doing some tests on mono+linux and everything works fine for my
>> > application except for the new routing module.
>> >
>> > In the routing rules i define the area as empty but the monorail
>> > handler seems to be ignoring it.
>> >
>> >
>> > in the Web.config I have added the following:
>> >
>> > <httpModules>
>> >
>> > <add name="routing"
>> >
>> type="Castle.MonoRail.Framework.Routing.RoutingModuleEx,Castle.MonoRail.Framework"/
>> >>
>> >
>> > </httpModules>
>> >
>> > In Global.asax I have added this rule for testing:
>> >
>> >
>> > private void Application_Start(object sender, EventArgs e)
>> > {
>> >
>> >
>> > RoutingModuleEx.Engine.Add(new
>> > PatternRoute("default","<community>/<controller>/
>> > <action>.rails").DefaultForArea().IsEmpty.DefaultForController().Is
>> > ("Home").
>> > DefaultForAction().Is("Index").DefaultFor("community").Is("1"));
>> >
>> > }
>> >
>> > When I try the url for that route i get a
>> > ControllerNotFoundException.
>> >
>> > http://localhost/1/home/index.rails
>> >
>> > Controller not found. Area: '1' Controller Name: 'home'
>> >
>> > Description: HTTP 500. Error processing request.
>> >
>> > Stack Trace:
>> >
>> > Castle.MonoRail.Framework.ControllerNotFoundException: Controller not
>> > found. Area: '1' Controller Name: 'home'
>> > at Castle.MonoRail.Framework.MonoRailHttpHandlerFactory
>> > +NotFoundHandler.ProcessRequest (System.Web.HttpContext context)
>> > [0x00000]
>> > at System.Web.HttpApplication+<Pipeline>c__Iterator2.MoveNext ()
>> > [0x00000]
>> > at System.Web.HttpApplication.Tick () [0x00000]
>> >
>> > The same code works fine on Windows
>> >
>> > The only PatternRoutes that do something are such like:
>> >
>> > PatternRoute("default","<controller>/<action>.rails").DefaultForArea
>> > ().IsEmpty.DefaultForController().Is("Home").D
>> > efaultForAction().Is("Index"));
>> >
>> > (works with the url: http://localhost/Home/index.rails)
>> >
>> > PatternRoute("default2","<action>.rails").DefaultForArea
>> > ().IsEmpty.DefaultForController().Is("Home").D
>> > efaultForAction().Is("Index"));
>> >
>> > (works with the url: http://localhost/index.rails)
>> >
>> > PatternRoute("default3","<community>.rails").DefaultForArea
>> > ().IsEmpty.DefaultForController().Is("Home").D
>> > efaultForAction().Is("Index").DefaultFor("community").Is("1"));
>> >
>> > (works with the url: http://localhost/1.rails)
>> >
>> >
>> > Any thing else gives the mentioned ControllerNotFoundException
>> >
>> > Any ideas?
>> > Thanks.
>> >
>> > >
>> >
>>
>>
>>
>> --
>>
>> Ricardo Lopes
>> >>
>>
--
Ricardo Lopes
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Castle Project Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/castle-project-users?hl=en
-~----------~----~----~----~------~----~------~--~---
using System;
using System.IO;
using System.Web;
using System.Web.Configuration;
using Castle.MonoRail.Framework;
using Castle.MonoRail.Framework.Adapters;
using Castle.MonoRail.Framework.Routing;
namespace I9P.FindAPlayer.Web
{
public class MonoRoutingModuleEx : IHttpModule
{
private static readonly RoutingEngine engine = new RoutingEngine();
private string defaultUrlExtension = ".castle";
/// <summary>
/// Inits the specified app.
/// </summary>
/// <param name="app">The app.</param>
public void Init(HttpApplication app)
{
app.BeginRequest += OnBeginRequest;
try
{
HttpHandlersSection httpHandlersConfig =
(HttpHandlersSection)WebConfigurationManager.GetSection("system.web/httpHandlers");
foreach (HttpHandlerAction handlerAction in httpHandlersConfig.Handlers)
{
if (typeof(MonoRailHttpHandlerFactory).IsAssignableFrom(Type.GetType(handlerAction.Type)))
{
if (handlerAction.Path.StartsWith("*."))
{
defaultUrlExtension = handlerAction.Path.Substring(1);
break;
}
else if (handlerAction.Path == "*")
{
defaultUrlExtension = string.Empty;
}
}
}
}
catch
{
//just swallow and keep on using .castle as the default.
}
}
/// <summary>
/// Disposes of the resources (other than memory)
/// used by the module that implements <see cref="T:System.Web.IHttpModule"/>.
/// </summary>
public void Dispose()
{
}
/// <summary>
/// Called when [begin request].
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
public void OnBeginRequest(object sender, EventArgs e)
{
HttpContext current = HttpContext.Current;
HttpRequest request = current.Request;
HttpResponse response = current.Response;
if (! File.Exists(request.PhysicalPath))
{
RouteMatch match = engine.FindMatch(this.StripAppPathFrom(request.FilePath, request.ApplicationPath) + request.PathInfo,
new RouteContext(new RequestAdapter(request), response, request.ApplicationPath, current.Items));
if (((match != null) && (response.StatusCode != 0x12d)) && (response.StatusCode != 0x12e))
{
string filePath = CreateMonoRailPath(match);
string rawUrl = request.RawUrl;
string queryString = "";
int index = rawUrl.IndexOf('?');
if (index != -1)
{
queryString = rawUrl.Substring(index + 1);
}
if (queryString.Length != 0)
{
current.RewritePath(filePath, request.PathInfo, queryString);
}
else
{
current.RewritePath(filePath);
}
current.Items.Add(RouteMatch.RouteMatchKey, match);
}
}
}
private string StripAppPathFrom(string path, string applicationPath)
{
if (applicationPath.Length != 1)
{
return path.Substring(applicationPath.Length);
}
return path;
}
private string CreateMonoRailPath(RouteMatch match)
{
if (!match.Parameters.ContainsKey("controller"))
{
throw new MonoRailException(
"Parameter 'controller' is not optional. Check your routing rules to make " +
"sure this parameter is being added to the RouteMatch");
}
if (!match.Parameters.ContainsKey("action"))
{
throw new MonoRailException(
"Parameter 'action' is not optional. Check your routing rules to make " +
"sure this parameter is being added to the RouteMatch");
}
string controller = match.Parameters["controller"];
string area = match.Parameters.ContainsKey("area") ? match.Parameters["area"] : null;
string action = match.Parameters["action"];
if (! string.IsNullOrEmpty(area))
{
return "/" + area + "/" + controller + "/" + action + defaultUrlExtension;
}
else
{
return "/" + controller + "/" + action + defaultUrlExtension;
}
}
/// <summary>
/// Gets the engine.
/// </summary>
/// <value>The engine.</value>
public static RoutingEngine Engine
{
get { return engine; }
}
}
}