diff --git a/src/Umbraco.Core/Configuration/GlobalSettings.cs b/src/Umbraco.Core/Configuration/GlobalSettings.cs index d2fca6eb36..10446c7f5c 100644 --- a/src/Umbraco.Core/Configuration/GlobalSettings.cs +++ b/src/Umbraco.Core/Configuration/GlobalSettings.cs @@ -154,6 +154,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 { @@ -163,7 +166,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 e8d5fc0628..6ea6b93e38 100644 --- a/src/Umbraco.Tests/GlobalSettingsTests.cs +++ b/src/Umbraco.Tests/GlobalSettingsTests.cs @@ -2,6 +2,7 @@ using System.Configuration; using System.Web.Routing; using NUnit.Framework; using Umbraco.Core.Configuration; +using Umbraco.Core.IO; using Umbraco.Tests.TestHelpers; using System.Web.Mvc; @@ -23,6 +24,9 @@ namespace Umbraco.Tests public override void TearDown() { + //ensure this is reset + SystemDirectories.Root = null; + SettingsForTests.UmbracoPath = "~/umbraco"; //reset the app config base.TearDown(); @@ -35,7 +39,19 @@ namespace Umbraco.Tests Assert.That(UmbracoVersion.Current.ToString(3), Is.EqualTo("6.0.0")); } - [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 7b61fcdea8..93e7035e83 100644 --- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj +++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj @@ -2469,7 +2469,7 @@ xcopy "$(ProjectDir)"..\packages\SqlServerCE.4.0.0.0\x86\*.* "$(TargetDir)x86\" True 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 cd6601ec6c..ee58adf327 100644 --- a/src/Umbraco.Web/UriUtility.cs +++ b/src/Umbraco.Web/UriUtility.cs @@ -51,7 +51,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 = "/";