From 04b96077414e8bf1aabb8cc0c7184f8bb7322707 Mon Sep 17 00:00:00 2001 From: Shannon Deminick Date: Fri, 15 Mar 2013 08:03:19 +0400 Subject: [PATCH] Fixes: #U4-1916 and another issue for vdirs, added unit tests, changed UI web project to always launch in a VDIR. --- .../Configuration/GlobalSettings.cs | 5 ++++- src/Umbraco.Core/IO/SystemDirectories.cs | 18 ++++++++++++++---- src/Umbraco.Tests/GlobalSettingsTests.cs | 18 +++++++++++++++++- src/Umbraco.Web.UI/Umbraco.Web.UI.csproj | 2 +- src/Umbraco.Web/UriUtility.cs | 2 +- 5 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/Umbraco.Core/Configuration/GlobalSettings.cs b/src/Umbraco.Core/Configuration/GlobalSettings.cs index f207f1dec7..cb032fabf2 100644 --- a/src/Umbraco.Core/Configuration/GlobalSettings.cs +++ b/src/Umbraco.Core/Configuration/GlobalSettings.cs @@ -156,6 +156,9 @@ namespace Umbraco.Core.Configuration /// This will return the MVC area that we will route all custom routes through like surface controllers, etc... /// We will use the 'Path' (default ~/umbraco) to create it but since it cannot contain '/' and people may specify a path of ~/asdf/asdf/admin /// we will convert the '/' to '-' and use that as the path. its a bit lame but will work. + /// + /// We also make sure that the virtual directory (SystemDirectories.Root) is stripped off first, otherwise we'd end up with something + /// like "MyVirtualDirectory-Umbraco" instead of just "Umbraco". /// internal static string UmbracoMvcArea { @@ -165,7 +168,7 @@ namespace Umbraco.Core.Configuration { throw new InvalidOperationException("Cannot create an MVC Area path without the umbracoPath specified"); } - return Path.TrimStart('~').TrimStart('/').Replace('/', '-').Trim(); + return Path.TrimStart(SystemDirectories.Root).TrimStart('~').TrimStart('/').Replace('/', '-').Trim().ToLower(); } } diff --git a/src/Umbraco.Core/IO/SystemDirectories.cs b/src/Umbraco.Core/IO/SystemDirectories.cs index e70046c90e..433d01c206 100644 --- a/src/Umbraco.Core/IO/SystemDirectories.cs +++ b/src/Umbraco.Core/IO/SystemDirectories.cs @@ -183,16 +183,26 @@ namespace Umbraco.Core.IO } } + private static string _root; + /// + /// Gets the root path of the application + /// public static string Root { get { - string appPath = HttpRuntime.AppDomainAppVirtualPath ?? string.Empty; - if (appPath == "/") - appPath = string.Empty; + if (_root == null) + { + string appPath = HttpRuntime.AppDomainAppVirtualPath ?? string.Empty; + if (appPath == "/") + appPath = string.Empty; - return appPath; + _root = appPath; + } + return _root; } + //Only required for unit tests + internal set { _root = value; } } } diff --git a/src/Umbraco.Tests/GlobalSettingsTests.cs b/src/Umbraco.Tests/GlobalSettingsTests.cs index ffffd11912..f2654ef722 100644 --- a/src/Umbraco.Tests/GlobalSettingsTests.cs +++ b/src/Umbraco.Tests/GlobalSettingsTests.cs @@ -1,6 +1,7 @@ using System.Configuration; using System.Web.Routing; using NUnit.Framework; +using Umbraco.Core.IO; using Umbraco.Tests.TestHelpers; using System.Web.Mvc; @@ -22,12 +23,27 @@ namespace Umbraco.Tests public override void TearDown() { + //ensure this is reset + SystemDirectories.Root = null; + SettingsForTests.UmbracoPath = "~/umbraco"; //reset the app config base.TearDown(); } - [TestCase("/umbraco/umbraco.aspx")] + [TestCase("~/umbraco", "/", "umbraco")] + [TestCase("~/umbraco", "/MyVirtualDir", "umbraco")] + [TestCase("~/customPath", "/MyVirtualDir/", "custompath")] + [TestCase("~/some-wacky/nestedPath", "/MyVirtualDir", "some-wacky-nestedpath")] + [TestCase("~/some-wacky/nestedPath", "/MyVirtualDir/NestedVDir/", "some-wacky-nestedpath")] + public void Umbraco_Mvc_Area(string path, string rootPath, string outcome) + { + SettingsForTests.UmbracoPath = path; + SystemDirectories.Root = rootPath; + Assert.AreEqual(outcome, Umbraco.Core.Configuration.GlobalSettings.UmbracoMvcArea); + } + + [TestCase("/umbraco/umbraco.aspx")] [TestCase("/umbraco/editContent.aspx")] [TestCase("/install/default.aspx")] [TestCase("/install/")] diff --git a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj index 3955dc6add..3dbba44e9c 100644 --- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj +++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj @@ -2391,7 +2391,7 @@ xcopy "$(ProjectDir)"..\..\lib\SQLCE4\x86\*.* "$(TargetDir)x86\" /Y /F /E /DTrue 61637 / - http://localhost:61638/ + http://localhost:61639/VirtualDir False False diff --git a/src/Umbraco.Web/UriUtility.cs b/src/Umbraco.Web/UriUtility.cs index 7b5833f606..02cf89cbaa 100644 --- a/src/Umbraco.Web/UriUtility.cs +++ b/src/Umbraco.Web/UriUtility.cs @@ -52,7 +52,7 @@ namespace Umbraco.Web // see also VirtualPathUtility.ToAppRelative public static string ToAppRelative(string virtualPath) { - if (virtualPath.StartsWith(_appPathPrefix)) + if (virtualPath.InvariantStartsWith(_appPathPrefix)) virtualPath = virtualPath.Substring(_appPathPrefix.Length); if (virtualPath.Length == 0) virtualPath = "/";