This project is read-only.

RouteDescriptor.Name does not work in Multi-Tenancy Situations

Topics: Core
Jun 7, 2013 at 10:01 AM
I think I've identified an issue with RouteDescriptors that relates to multi-tenancy environments.

The code below works perfectly well on a single tenant, or if only one tenant has this module enabled
public class ErrorHandlingRoutesProvider : IRouteProvider
        public IEnumerable<RouteDescriptor> GetRoutes()
            return new[]{ 
                new RouteDescriptor{
                    //this route should be matched if no other routes match- this allows us to throw 404 exceptions
                    Name = "ErrorRoute",
                    Priority = 1,                    
                    Route = new Route(
                        new RouteValueDictionary{
                            {"action", "ErrorPage"},
                            {"controller", "ErrorHandler"},
                            {"area", "BedeGaming.Shared.ErrorHandling"}
                        new RouteValueDictionary(),//constraints (none here)
                        new RouteValueDictionary{
                            {"area", "BedeGaming.Shared.ErrorHandling"}
                        new MvcRouteHandler())
                } ,
If another tenant tries to activate the module, we get the following error:
2013-06-06 16:40:16,410 [82] Orchard.Environment.DefaultOrchardHost - A tenant could not be started: xxxxxxx
System.ArgumentException: A route named 'ErrorRoute' is already in the route collection. Route names must be unique.
Parameter name: name
   at System.Web.Routing.RouteCollection.Add(String name, RouteBase item)
   at Orchard.Mvc.Routes.RoutePublisher.Publish(IEnumerable`1 routes) in d:\Workspaces\GitHub\src\Orchard\Mvc\Routes\RoutePublisher.cs:line 100
   at Orchard.Environment.DefaultOrchardShell.Activate() in d:\Workspaces\GitHub\src\Orchard\Environment\DefaultOrchardShell.cs:line 48
   at Orchard.Environment.DefaultOrchardHost.ActivateShell(ShellContext context) in d:\Workspaces\GitHub\src\Orchard\Environment\DefaultOrchardHost.cs:line 156
   at Orchard.Environment.DefaultOrchardHost.CreateAndActivateShells() in d:\Workspaces\GitHub\src\Orchard\Environment\DefaultOrchardHost.cs:line 135
It appears that the route is registered globally, not for the current tenant activating the module. This can be worked around by removing the Name attribute for the route.

There appears to be a related post, where I'm guessing the module author resolved the issue by removing the name.

Instinct says this is not as intended, but I could be wrong, and "Named" routes are intended to be global. (unlikely though as modules in a tenant could therefore affect the landlord).

Would someone from the core dev team chip in? Just let me know if I should raise an issue for this item.
Jun 7, 2013 at 6:59 PM
I am almost sure the bug as already been filed by Piedone.
Jun 7, 2013 at 7:02 PM
This sounds like a bug, would you mind raising an issue (unless there's already one)?
Jun 7, 2013 at 10:48 PM
Jun 11, 2013 at 2:16 PM
thanks - I've voted it up