mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-12-02 19:44:02 +08:00
#18793: Added support for turning session-state or/off on routes implementing IRouteWithArea.
Fixed a bug with incorrect property from which the extensionId is retrieved. Fixed unit tests to check if session state is parsed correctly. Work Item: 18793 --HG-- branch : 1.x
This commit is contained in:
@@ -141,6 +141,7 @@ namespace Orchard.Tests.Environment.Extensions {
|
|||||||
|
|
||||||
_folders.Manifests.Add("Sample", @"
|
_folders.Manifests.Add("Sample", @"
|
||||||
NaMe: Sample Extension
|
NaMe: Sample Extension
|
||||||
|
SESSIONSTATE: disabled
|
||||||
version: 2.x
|
version: 2.x
|
||||||
DESCRIPTION: HELLO
|
DESCRIPTION: HELLO
|
||||||
");
|
");
|
||||||
@@ -150,6 +151,7 @@ DESCRIPTION: HELLO
|
|||||||
Assert.That(descriptor.Name, Is.EqualTo("Sample Extension"));
|
Assert.That(descriptor.Name, Is.EqualTo("Sample Extension"));
|
||||||
Assert.That(descriptor.Version, Is.EqualTo("2.x"));
|
Assert.That(descriptor.Version, Is.EqualTo("2.x"));
|
||||||
Assert.That(descriptor.Description, Is.EqualTo("HELLO"));
|
Assert.That(descriptor.Description, Is.EqualTo("HELLO"));
|
||||||
|
Assert.That(descriptor.SessionState, Is.EqualTo("disabled"));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -193,6 +195,7 @@ Features:
|
|||||||
|
|
||||||
_folders.Manifests.Add("MyCompany.AnotherWiki", @"
|
_folders.Manifests.Add("MyCompany.AnotherWiki", @"
|
||||||
Name: AnotherWiki
|
Name: AnotherWiki
|
||||||
|
SessionState: required
|
||||||
Author: Coder Notaprogrammer
|
Author: Coder Notaprogrammer
|
||||||
Website: http://anotherwiki.codeplex.com
|
Website: http://anotherwiki.codeplex.com
|
||||||
Version: 1.2.3
|
Version: 1.2.3
|
||||||
@@ -224,6 +227,7 @@ Features:
|
|||||||
Assert.That(descriptor.Version, Is.EqualTo("1.2.3"));
|
Assert.That(descriptor.Version, Is.EqualTo("1.2.3"));
|
||||||
Assert.That(descriptor.OrchardVersion, Is.EqualTo("1"));
|
Assert.That(descriptor.OrchardVersion, Is.EqualTo("1"));
|
||||||
Assert.That(descriptor.Features.Count(), Is.EqualTo(5));
|
Assert.That(descriptor.Features.Count(), Is.EqualTo(5));
|
||||||
|
Assert.That(descriptor.SessionState, Is.EqualTo("required"));
|
||||||
foreach (var featureDescriptor in descriptor.Features) {
|
foreach (var featureDescriptor in descriptor.Features) {
|
||||||
switch (featureDescriptor.Id) {
|
switch (featureDescriptor.Id) {
|
||||||
case "AnotherWiki":
|
case "AnotherWiki":
|
||||||
|
|||||||
@@ -2,11 +2,13 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Web.Http;
|
using System.Web.Http;
|
||||||
|
using System.Web.Mvc;
|
||||||
using System.Web.Routing;
|
using System.Web.Routing;
|
||||||
using System.Web.SessionState;
|
using System.Web.SessionState;
|
||||||
using Orchard.Environment;
|
using Orchard.Environment;
|
||||||
using Orchard.Environment.Configuration;
|
using Orchard.Environment.Configuration;
|
||||||
using Orchard.Environment.Extensions;
|
using Orchard.Environment.Extensions;
|
||||||
|
using Orchard.Environment.Extensions.Models;
|
||||||
|
|
||||||
namespace Orchard.Mvc.Routes {
|
namespace Orchard.Mvc.Routes {
|
||||||
public class RoutePublisher : IRoutePublisher {
|
public class RoutePublisher : IRoutePublisher {
|
||||||
@@ -67,17 +69,24 @@ namespace Orchard.Mvc.Routes {
|
|||||||
// Loading session state information.
|
// Loading session state information.
|
||||||
var defaultSessionState = SessionStateBehavior.Default;
|
var defaultSessionState = SessionStateBehavior.Default;
|
||||||
|
|
||||||
|
ExtensionDescriptor extensionDescriptor = null;
|
||||||
if(routeDescriptor.Route is Route) {
|
if(routeDescriptor.Route is Route) {
|
||||||
object extensionId;
|
object extensionId;
|
||||||
var routeCasted = routeDescriptor.Route as Route;
|
var route = routeDescriptor.Route as Route;
|
||||||
if(routeCasted != null && routeCasted.Constraints != null && routeCasted.Constraints.TryGetValue("area", out extensionId)) {
|
if(route.DataTokens != null && route.DataTokens.TryGetValue("area", out extensionId) ||
|
||||||
var extensionDescriptor = _extensionManager.GetExtension(extensionId.ToString());
|
route.Defaults != null && route.Defaults.TryGetValue("area", out extensionId)) {
|
||||||
if(extensionDescriptor != null) {
|
extensionDescriptor = _extensionManager.GetExtension(extensionId.ToString());
|
||||||
// if session state is not define explicitly, use the one define for the extension
|
}
|
||||||
if(routeDescriptor.SessionState == SessionStateBehavior.Default) {
|
}
|
||||||
Enum.TryParse(extensionDescriptor.SessionState, true /*ignoreCase*/, out defaultSessionState);
|
else if(routeDescriptor.Route is IRouteWithArea) {
|
||||||
}
|
var route = routeDescriptor.Route as IRouteWithArea;
|
||||||
}
|
extensionDescriptor = _extensionManager.GetExtension(route.Area);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (extensionDescriptor != null) {
|
||||||
|
// if session state is not define explicitly, use the one define for the extension
|
||||||
|
if (routeDescriptor.SessionState == SessionStateBehavior.Default) {
|
||||||
|
Enum.TryParse(extensionDescriptor.SessionState, true /*ignoreCase*/, out defaultSessionState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,7 +101,5 @@ namespace Orchard.Mvc.Routes {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user