mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-12-02 11:44:41 +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", @"
|
||||
NaMe: Sample Extension
|
||||
SESSIONSTATE: disabled
|
||||
version: 2.x
|
||||
DESCRIPTION: HELLO
|
||||
");
|
||||
@@ -150,6 +151,7 @@ DESCRIPTION: HELLO
|
||||
Assert.That(descriptor.Name, Is.EqualTo("Sample Extension"));
|
||||
Assert.That(descriptor.Version, Is.EqualTo("2.x"));
|
||||
Assert.That(descriptor.Description, Is.EqualTo("HELLO"));
|
||||
Assert.That(descriptor.SessionState, Is.EqualTo("disabled"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -193,6 +195,7 @@ Features:
|
||||
|
||||
_folders.Manifests.Add("MyCompany.AnotherWiki", @"
|
||||
Name: AnotherWiki
|
||||
SessionState: required
|
||||
Author: Coder Notaprogrammer
|
||||
Website: http://anotherwiki.codeplex.com
|
||||
Version: 1.2.3
|
||||
@@ -224,6 +227,7 @@ Features:
|
||||
Assert.That(descriptor.Version, Is.EqualTo("1.2.3"));
|
||||
Assert.That(descriptor.OrchardVersion, Is.EqualTo("1"));
|
||||
Assert.That(descriptor.Features.Count(), Is.EqualTo(5));
|
||||
Assert.That(descriptor.SessionState, Is.EqualTo("required"));
|
||||
foreach (var featureDescriptor in descriptor.Features) {
|
||||
switch (featureDescriptor.Id) {
|
||||
case "AnotherWiki":
|
||||
|
||||
@@ -2,11 +2,13 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web.Http;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
using System.Web.SessionState;
|
||||
using Orchard.Environment;
|
||||
using Orchard.Environment.Configuration;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
|
||||
namespace Orchard.Mvc.Routes {
|
||||
public class RoutePublisher : IRoutePublisher {
|
||||
@@ -67,17 +69,24 @@ namespace Orchard.Mvc.Routes {
|
||||
// Loading session state information.
|
||||
var defaultSessionState = SessionStateBehavior.Default;
|
||||
|
||||
ExtensionDescriptor extensionDescriptor = null;
|
||||
if(routeDescriptor.Route is Route) {
|
||||
object extensionId;
|
||||
var routeCasted = routeDescriptor.Route as Route;
|
||||
if(routeCasted != null && routeCasted.Constraints != null && routeCasted.Constraints.TryGetValue("area", out extensionId)) {
|
||||
var extensionDescriptor = _extensionManager.GetExtension(extensionId.ToString());
|
||||
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);
|
||||
}
|
||||
}
|
||||
var route = routeDescriptor.Route as Route;
|
||||
if(route.DataTokens != null && route.DataTokens.TryGetValue("area", out extensionId) ||
|
||||
route.Defaults != null && route.Defaults.TryGetValue("area", out extensionId)) {
|
||||
extensionDescriptor = _extensionManager.GetExtension(extensionId.ToString());
|
||||
}
|
||||
}
|
||||
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