mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
20592: Fixing named routes support
Work Item:20592
This commit is contained in:
committed by
Sebastien Ros
parent
abd91fd2f7
commit
b1d97f3ad5
@@ -93,6 +93,17 @@ namespace Orchard.Tests.Mvc {
|
||||
Assert.That(where, Is.EqualTo("after"));
|
||||
action.EndInvoke(asyncResult);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RouteDescriptorWithNameCreatesNamedRouteInCollection() {
|
||||
_routes.MapRoute("foo", "{controller}");
|
||||
|
||||
var publisher = _container.Resolve<IRoutePublisher>();
|
||||
var routeDescriptor = Desc("yarg", "bar");
|
||||
publisher.Publish(new[] { routeDescriptor });
|
||||
|
||||
Assert.That(_routes["yarg"], Is.Not.Null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Web.Http;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
@@ -52,15 +53,19 @@ namespace Orchard.Mvc.Routes {
|
||||
|
||||
preloading.Add(routeDescriptor.Name, routeDescriptor.Route);
|
||||
}
|
||||
|
||||
|
||||
|
||||
using (_routeCollection.GetWriteLock()) {
|
||||
// existing routes are removed while the collection is briefly inaccessable
|
||||
_routeCollection
|
||||
.OfType<HubRoute>()
|
||||
.ForEach(x => x.ReleaseShell(_shellSettings));
|
||||
|
||||
// new routes are added
|
||||
|
||||
// HACK: For inserting names in internal dictionary when inserting route to RouteCollection.
|
||||
var routeCollectionType = typeof (RouteCollection);
|
||||
var namedMap = (Dictionary<string, RouteBase>) routeCollectionType.GetField("_namedMap", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(_routeCollection);
|
||||
|
||||
// new routes are added
|
||||
foreach (var routeDescriptor in routesArray) {
|
||||
// Loading session state information.
|
||||
var defaultSessionState = SessionStateBehavior.Default;
|
||||
@@ -120,6 +125,11 @@ namespace Orchard.Mvc.Routes {
|
||||
}
|
||||
|
||||
_routeCollection.Insert(index, matchedHubRoute);
|
||||
|
||||
// HACK: For inserting names in internal dictionary when inserting route to RouteCollection.
|
||||
if (!string.IsNullOrEmpty(matchedHubRoute.Name) && !namedMap.ContainsKey(matchedHubRoute.Name)) {
|
||||
namedMap[matchedHubRoute.Name] = matchedHubRoute;
|
||||
}
|
||||
}
|
||||
|
||||
matchedHubRoute.Add(shellRoute, _shellSettings);
|
||||
|
||||
Reference in New Issue
Block a user