diff --git a/src/Umbraco.Tests/DocumentLookups/LookupByNiceUrlAndTemplateTests.cs b/src/Umbraco.Tests/DocumentLookups/LookupByNiceUrlAndTemplateTests.cs
new file mode 100644
index 0000000000..f221b5a0da
--- /dev/null
+++ b/src/Umbraco.Tests/DocumentLookups/LookupByNiceUrlAndTemplateTests.cs
@@ -0,0 +1,33 @@
+using NUnit.Framework;
+using Umbraco.Web.Routing;
+using umbraco.BusinessLogic;
+using umbraco.cms.businesslogic.template;
+
+namespace Umbraco.Tests.DocumentLookups
+{
+ [TestFixture]
+ public class LookupByNiceUrlAndTemplateTests : BaseRoutingTest
+ {
+ [TestCase("/blah")]
+ [TestCase("/default.aspx/blah")] //this one is actually rather important since this is the path that comes through when we are running in pre-IIS 7 for the root document '/' !
+ [TestCase("/home/Sub1/blah")]
+ [TestCase("/Home/Sub1/Blah")] //different cases
+ [TestCase("/home/Sub1.aspx/blah")]
+ public void Match_Document_By_Url_With_Template(string urlAsString)
+ {
+ var template = Template.MakeNew("test", new User(0));
+ var altTemplate = Template.MakeNew("blah", new User(0));
+ var routingContext = GetRoutingContext(urlAsString, template);
+ var url = routingContext.UmbracoContext.UmbracoUrl; //very important to use the cleaned up umbraco url
+ var docRequest = new DocumentRequest(url, routingContext);
+ var lookup = new LookupByNiceUrlAndTemplate();
+
+ var result = lookup.TrySetDocument(docRequest);
+
+ Assert.IsTrue(result);
+ Assert.IsNotNull(docRequest.Node);
+ Assert.IsNotNull(docRequest.Template);
+ Assert.AreEqual("blah".ToUpperInvariant(), docRequest.Template.Alias.ToUpperInvariant());
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Umbraco.Tests/DocumentLookups/LookupByNiceUrlTests.cs b/src/Umbraco.Tests/DocumentLookups/LookupByNiceUrlTests.cs
index 7633b9d13e..d41ae6a3fa 100644
--- a/src/Umbraco.Tests/DocumentLookups/LookupByNiceUrlTests.cs
+++ b/src/Umbraco.Tests/DocumentLookups/LookupByNiceUrlTests.cs
@@ -16,7 +16,7 @@ namespace Umbraco.Tests.DocumentLookups
[TestCase("/Sub1")]
[TestCase("/sub1")]
[TestCase("/sub1.aspx")]
- public void Match_Document_By_Directory_Url_Hide_Top_Level(string urlAsString)
+ public void Match_Document_By_Url_Hide_Top_Level(string urlAsString)
{
var template = Template.MakeNew("test", new User(0));
var routingContext = GetRoutingContext(urlAsString, template);
@@ -36,7 +36,7 @@ namespace Umbraco.Tests.DocumentLookups
[TestCase("/home/Sub1")]
[TestCase("/Home/Sub1")] //different cases
[TestCase("/home/Sub1.aspx")]
- public void Match_Document_By_Directory_Url(string urlAsString)
+ public void Match_Document_By_Url(string urlAsString)
{
var template = Template.MakeNew("test", new User(0));
var routingContext = GetRoutingContext(urlAsString, template);
diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj
index 6ff3fc2256..4c7ecb53c1 100644
--- a/src/Umbraco.Tests/Umbraco.Tests.csproj
+++ b/src/Umbraco.Tests/Umbraco.Tests.csproj
@@ -63,6 +63,7 @@
+
diff --git a/src/Umbraco.Tests/UriUtilityTests.cs b/src/Umbraco.Tests/UriUtilityTests.cs
index 6605d22885..eed7df2baa 100644
--- a/src/Umbraco.Tests/UriUtilityTests.cs
+++ b/src/Umbraco.Tests/UriUtilityTests.cs
@@ -14,6 +14,8 @@ namespace Umbraco.Tests
[TestCase("http://localhost/home/Sub1", "http://localhost/home/sub1")]
[TestCase("http://localhost/home/Sub1.aspx", "http://localhost/home/sub1")]
[TestCase("http://localhost/home/Sub1.aspx?test=blah", "http://localhost/home/sub1?test=blah")]
+ [TestCase("http://Localhost/home/sub1.aspx/blah", "http://localhost/home/sub1/blah")]
+ [TestCase("http://Localhost/home/sub1.aspx/blah?test=asdf", "http://localhost/home/sub1/blah?test=asdf")]
public void Uri_To_Umbraco(string url, string expected)
{
var uri = new Uri(url);
diff --git a/src/Umbraco.Web/UriUtility.cs b/src/Umbraco.Web/UriUtility.cs
index 8368ab26ce..596228e10d 100644
--- a/src/Umbraco.Web/UriUtility.cs
+++ b/src/Umbraco.Web/UriUtility.cs
@@ -76,14 +76,18 @@ namespace Umbraco.Web
//we need to check if the path is /default.aspx because this will occur when using a
//web server pre IIS 7 when requesting the root document
//if this is the case we need to change it to '/'
- if (path.EndsWith("default.aspx", StringComparison.InvariantCultureIgnoreCase))
+ if (path.StartsWith("/default.aspx", StringComparison.InvariantCultureIgnoreCase))
{
- path = path.Substring(0, path.Length - "default.aspx".Length);
+ path = "/" + path.Substring("/default.aspx".Length, path.Length - "/default.aspx".Length);
}
if (path != "/")
path = path.TrimEnd('/');
- if (path.EndsWith(".aspx"))
- path = path.Substring(0, path.Length - ".aspx".Length);
+
+ //if any part of the path contains .aspx, replace it with nothing.
+ //sometimes .aspx is not at the end since we might have /home/sub1.aspx/customtemplate
+ path = path.Replace(".aspx", "");
+ //if (path.EndsWith(".aspx"))
+ // path = path.Substring(0, path.Length - ".aspx".Length);
return uri.Rewrite(path);
}