public class ErrorHandlingRoutesProvider : IRouteProvider { public IEnumerable<routedescriptor> GetRoutes() { return new[]{ new RouteDescriptor{ Name = "ErrorRoute", Priority = 1, Route = new Route( "Error", new RouteValueDictionary{ {"action", "ErrorPage"}, {"controller", "ErrorHandler"}, {"area", "BG.Shared.ErrorHandling"} }, new RouteValueDictionary(),//constraints (none here) new RouteValueDictionary{ {"area", "BG.Shared.ErrorHandling"} }, new MvcRouteHandler()) }; }
This works as intended in a single site. However, when you have two tenants using the same module, this will fail with an error similar to the following:
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
The workaround is to comment out the "Name" attribute of the RouteDescriptor, as follows
public IEnumerable<RouteDescriptor> GetRoutes() { return new[]{ new RouteDescriptor{ //Name = "ErrorRoute", //This doesn't work in Multi-Tenancy Priority = 1, Route = new Route( "Error", new RouteValueDictionary{ {"action", "ErrorPage"}, {"controller", "ErrorHandler"}, {"area", "BG.Shared.ErrorHandling"} }, new RouteValueDictionary(),//constraints (none here) new RouteValueDictionary{ {"area", "BG.Shared.ErrorHandling"} }, new MvcRouteHandler()) } }; }I've started investigating this with the Orchard team, but the workaround doesn't really appear to have any drawbacks.
This is already fixed, see: https://orchard.codeplex.com/workitem/19611
ReplyDelete