This commit is contained in:
Shannon Deminick
2012-10-01 02:48:39 +05:00
20 changed files with 438 additions and 234 deletions

View File

@@ -312,16 +312,21 @@ namespace Umbraco.Core.Configuration
get { return "packages.umbraco.org"; }
}
static bool? _useDomainPrefixes = null;
/// <summary>
/// Gets a value indicating whether umbraco will use domain prefixes.
/// </summary>
/// <value><c>true</c> if umbraco will use domain prefixes; otherwise, <c>false</c>.</value>
// TODO rename as EnforceAbsoluteUrls
public static bool UseDomainPrefixes
{
get
{
try
{
if (_useDomainPrefixes.HasValue)
return _useDomainPrefixes.Value;
bool result;
if (bool.TryParse(GetKey("/settings/requestHandler/useDomainPrefixes"), out result))
return result;
@@ -332,6 +337,11 @@ namespace Umbraco.Core.Configuration
return false;
}
}
// for unit tests only
internal set
{
_useDomainPrefixes = value;
}
}
static bool? _addTrailingSlash = null;
@@ -365,6 +375,7 @@ namespace Umbraco.Core.Configuration
return false;
}
}
// for unit tests only
internal set
{
_addTrailingSlash = value;

View File

@@ -66,76 +66,76 @@ namespace Umbraco.Tests.Routing
<!ATTLIST Doc id ID #REQUIRED>
]>
<root id=""-1"">
<Doc id=""1001"" parentID=""-1"" level=""1"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""1"" createDate=""2012-06-12T14:13:17"" updateDate=""2012-07-20T18:50:43"" nodeName=""Home"" urlName=""1001"" writerName=""admin"" creatorName=""admin"" path=""-1,1001"" isDoc="""">
<Doc id=""1001"" parentID=""-1"" level=""1"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""0"" createDate=""2012-06-12T14:13:17"" updateDate=""2012-07-20T18:50:43"" nodeName=""Home"" urlName=""1001"" writerName=""admin"" creatorName=""admin"" path=""-1,1001"" isDoc="""">
<content><![CDATA[]]></content>
<Doc id=""10011"" parentID=""1001"" level=""2"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""1"" createDate=""2012-07-20T18:06:45"" updateDate=""2012-07-20T19:07:31"" nodeName=""Sub1"" urlName=""1001-1"" writerName=""admin"" creatorName=""admin"" path=""-1,1001,10011"" isDoc="""">
<Doc id=""10011"" parentID=""1001"" level=""2"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""0"" createDate=""2012-07-20T18:06:45"" updateDate=""2012-07-20T19:07:31"" nodeName=""Sub1"" urlName=""1001-1"" writerName=""admin"" creatorName=""admin"" path=""-1,1001,10011"" isDoc="""">
<content><![CDATA[<div>This is some content</div>]]></content>
<Doc id=""100111"" parentID=""10011"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""1"" createDate=""2012-07-20T18:07:54"" updateDate=""2012-07-20T19:10:27"" nodeName=""Sub2"" urlName=""1001-1-1"" writerName=""admin"" creatorName=""admin"" path=""-1,1001,10011,100111"" isDoc="""">
<Doc id=""100111"" parentID=""10011"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""0"" createDate=""2012-07-20T18:07:54"" updateDate=""2012-07-20T19:10:27"" nodeName=""Sub2"" urlName=""1001-1-1"" writerName=""admin"" creatorName=""admin"" path=""-1,1001,10011,100111"" isDoc="""">
<content><![CDATA[]]></content>
</Doc>
<Doc id=""100112"" parentID=""10011"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""2"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""1001-1-2"" writerName=""admin"" creatorName=""admin"" path=""-1,1001,10011,100112"" isDoc="""">
<Doc id=""100112"" parentID=""10011"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""1"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""1001-1-2"" writerName=""admin"" creatorName=""admin"" path=""-1,1001,10011,100112"" isDoc="""">
<content><![CDATA[]]></content>
<Doc id=""1001121"" parentID=""100112"" level=""4"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""2"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""1001-1-2-1"" writerName=""admin"" creatorName=""admin"" path=""-1,1001,10011,100112,1001121"" isDoc="""">
<Doc id=""1001121"" parentID=""100112"" level=""4"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""1"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""1001-1-2-1"" writerName=""admin"" creatorName=""admin"" path=""-1,1001,10011,100112,1001121"" isDoc="""">
<content><![CDATA[]]></content>
</Doc>
<Doc id=""1001122"" parentID=""100112"" level=""4"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""2"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""1001-1-2-2"" writerName=""admin"" creatorName=""admin"" path=""-1,1001,10011,100112,1001122"" isDoc="""">
<Doc id=""1001122"" parentID=""100112"" level=""4"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""1"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""1001-1-2-2"" writerName=""admin"" creatorName=""admin"" path=""-1,1001,10011,100112,1001122"" isDoc="""">
<content><![CDATA[]]></content>
</Doc>
</Doc>
</Doc>
<Doc id=""10012"" parentID=""1001"" level=""2"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""2"" createDate=""2012-07-20T18:08:01"" updateDate=""2012-07-20T18:49:32"" nodeName=""Sub 2"" urlName=""1001-2"" writerName=""admin"" creatorName=""admin"" path=""-1,1001,10012"" isDoc="""">
<Doc id=""10012"" parentID=""1001"" level=""2"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""1"" createDate=""2012-07-20T18:08:01"" updateDate=""2012-07-20T18:49:32"" nodeName=""Sub 2"" urlName=""1001-2"" writerName=""admin"" creatorName=""admin"" path=""-1,1001,10012"" isDoc="""">
<content><![CDATA[<div>This is some content</div>]]></content>
<Doc id=""100121"" parentID=""10012"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""1"" createDate=""2012-07-20T18:07:54"" updateDate=""2012-07-20T19:10:27"" nodeName=""Sub2"" urlName=""1001-2-1"" writerName=""admin"" creatorName=""admin"" path=""-1,1001,10012,100121"" isDoc="""">
<Doc id=""100121"" parentID=""10012"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""0"" createDate=""2012-07-20T18:07:54"" updateDate=""2012-07-20T19:10:27"" nodeName=""Sub2"" urlName=""1001-2-1"" writerName=""admin"" creatorName=""admin"" path=""-1,1001,10012,100121"" isDoc="""">
<content><![CDATA[]]></content>
</Doc>
<Doc id=""100122"" parentID=""10012"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""2"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""1001-2-2"" writerName=""admin"" creatorName=""admin"" path=""-1,1001,10012,100122"" isDoc="""">
<Doc id=""100122"" parentID=""10012"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""1"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""1001-2-2"" writerName=""admin"" creatorName=""admin"" path=""-1,1001,10012,100122"" isDoc="""">
<content><![CDATA[]]></content>
<Doc id=""1001221"" parentID=""100122"" level=""4"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""2"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""1001-2-2-1"" writerName=""admin"" creatorName=""admin"" path=""-1,1001,10012,100122,1001221"" isDoc="""">
<Doc id=""1001221"" parentID=""100122"" level=""4"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""1"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""1001-2-2-1"" writerName=""admin"" creatorName=""admin"" path=""-1,1001,10012,100122,1001221"" isDoc="""">
<content><![CDATA[]]></content>
</Doc>
<Doc id=""1001222"" parentID=""100122"" level=""4"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""2"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""1001-2-2-2"" writerName=""admin"" creatorName=""admin"" path=""-1,1001,10012,100122,1001222"" isDoc="""">
<Doc id=""1001222"" parentID=""100122"" level=""4"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""1"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""1001-2-2-2"" writerName=""admin"" creatorName=""admin"" path=""-1,1001,10012,100122,1001222"" isDoc="""">
<content><![CDATA[]]></content>
</Doc>
</Doc>
</Doc>
<Doc id=""10013"" parentID=""1001"" level=""2"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""3"" createDate=""2012-07-20T18:08:01"" updateDate=""2012-07-20T18:49:32"" nodeName=""Sub 2"" urlName=""1001-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1001,10013"" isDoc="""">
<Doc id=""10013"" parentID=""1001"" level=""2"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""2"" createDate=""2012-07-20T18:08:01"" updateDate=""2012-07-20T18:49:32"" nodeName=""Sub 2"" urlName=""1001-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1001,10013"" isDoc="""">
</Doc>
</Doc>
<Doc id=""1002"" parentID=""-1"" level=""1"" writerID=""0"" creatorID=""0"" nodeType=""1234"" template=""" + templateId + @""" sortOrder=""3"" createDate=""2012-07-16T15:26:59"" updateDate=""2012-07-18T14:23:35"" nodeName=""Test"" urlName=""1002"" writerName=""admin"" creatorName=""admin"" path=""-1,1002"" isDoc="""">
<Doc id=""1002"" parentID=""-1"" level=""1"" writerID=""0"" creatorID=""0"" nodeType=""1234"" template=""" + templateId + @""" sortOrder=""2"" createDate=""2012-07-16T15:26:59"" updateDate=""2012-07-18T14:23:35"" nodeName=""Test"" urlName=""1002"" writerName=""admin"" creatorName=""admin"" path=""-1,1002"" isDoc="""">
</Doc>
<Doc id=""1003"" parentID=""-1"" level=""1"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""1"" createDate=""2012-06-12T14:13:17"" updateDate=""2012-07-20T18:50:43"" nodeName=""Home"" urlName=""1003"" writerName=""admin"" creatorName=""admin"" path=""-1,1003"" isDoc="""">
<Doc id=""1003"" parentID=""-1"" level=""1"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""0"" createDate=""2012-06-12T14:13:17"" updateDate=""2012-07-20T18:50:43"" nodeName=""Home"" urlName=""1003"" writerName=""admin"" creatorName=""admin"" path=""-1,1003"" isDoc="""">
<content><![CDATA[]]></content>
<Doc id=""10031"" parentID=""1003"" level=""2"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""1"" createDate=""2012-07-20T18:06:45"" updateDate=""2012-07-20T19:07:31"" nodeName=""Sub1"" urlName=""1003-1"" writerName=""admin"" creatorName=""admin"" path=""-1,1003,10031"" isDoc="""">
<Doc id=""10031"" parentID=""1003"" level=""2"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""0"" createDate=""2012-07-20T18:06:45"" updateDate=""2012-07-20T19:07:31"" nodeName=""Sub1"" urlName=""1003-1"" writerName=""admin"" creatorName=""admin"" path=""-1,1003,10031"" isDoc="""">
<content><![CDATA[<div>This is some content</div>]]></content>
<Doc id=""100311"" parentID=""10031"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""1"" createDate=""2012-07-20T18:07:54"" updateDate=""2012-07-20T19:10:27"" nodeName=""Sub2"" urlName=""1003-1-1"" writerName=""admin"" creatorName=""admin"" path=""-1,1003,10031,100311"" isDoc="""">
<Doc id=""100311"" parentID=""10031"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""0"" createDate=""2012-07-20T18:07:54"" updateDate=""2012-07-20T19:10:27"" nodeName=""Sub2"" urlName=""1003-1-1"" writerName=""admin"" creatorName=""admin"" path=""-1,1003,10031,100311"" isDoc="""">
<content><![CDATA[]]></content>
</Doc>
<Doc id=""100312"" parentID=""10031"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""2"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""1003-1-2"" writerName=""admin"" creatorName=""admin"" path=""-1,1003,10031,100312"" isDoc="""">
<Doc id=""100312"" parentID=""10031"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""1"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""1003-1-2"" writerName=""admin"" creatorName=""admin"" path=""-1,1003,10031,100312"" isDoc="""">
<content><![CDATA[]]></content>
<Doc id=""1003121"" parentID=""100312"" level=""4"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""2"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""1003-1-2-1"" writerName=""admin"" creatorName=""admin"" path=""-1,1003,10031,100312,1003121"" isDoc="""">
<Doc id=""1003121"" parentID=""100312"" level=""4"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""1"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""1003-1-2-1"" writerName=""admin"" creatorName=""admin"" path=""-1,1003,10031,100312,1003121"" isDoc="""">
<content><![CDATA[]]></content>
</Doc>
<Doc id=""1003122"" parentID=""100312"" level=""4"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""2"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""1003-1-2-2"" writerName=""admin"" creatorName=""admin"" path=""-1,1003,10031,100312,1003122"" isDoc="""">
<Doc id=""1003122"" parentID=""100312"" level=""4"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""1"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""1003-1-2-2"" writerName=""admin"" creatorName=""admin"" path=""-1,1003,10031,100312,1003122"" isDoc="""">
<content><![CDATA[]]></content>
</Doc>
</Doc>
</Doc>
<Doc id=""10032"" parentID=""1003"" level=""2"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""2"" createDate=""2012-07-20T18:08:01"" updateDate=""2012-07-20T18:49:32"" nodeName=""Sub 2"" urlName=""1003-2"" writerName=""admin"" creatorName=""admin"" path=""-1,1003,10032"" isDoc="""">
<Doc id=""10032"" parentID=""1003"" level=""2"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""1"" createDate=""2012-07-20T18:08:01"" updateDate=""2012-07-20T18:49:32"" nodeName=""Sub 2"" urlName=""1003-2"" writerName=""admin"" creatorName=""admin"" path=""-1,1003,10032"" isDoc="""">
<content><![CDATA[<div>This is some content</div>]]></content>
<Doc id=""100321"" parentID=""10032"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""1"" createDate=""2012-07-20T18:07:54"" updateDate=""2012-07-20T19:10:27"" nodeName=""Sub2"" urlName=""1003-2-1"" writerName=""admin"" creatorName=""admin"" path=""-1,1003,10032,100321"" isDoc="""">
<Doc id=""100321"" parentID=""10032"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""0"" createDate=""2012-07-20T18:07:54"" updateDate=""2012-07-20T19:10:27"" nodeName=""Sub2"" urlName=""1003-2-1"" writerName=""admin"" creatorName=""admin"" path=""-1,1003,10032,100321"" isDoc="""">
<content><![CDATA[]]></content>
</Doc>
<Doc id=""100322"" parentID=""10032"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""2"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""1003-2-2"" writerName=""admin"" creatorName=""admin"" path=""-1,1003,10032,100322"" isDoc="""">
<Doc id=""100322"" parentID=""10032"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""1"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""1003-2-2"" writerName=""admin"" creatorName=""admin"" path=""-1,1003,10032,100322"" isDoc="""">
<content><![CDATA[]]></content>
<Doc id=""1003221"" parentID=""100322"" level=""4"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""2"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""1003-2-2-1"" writerName=""admin"" creatorName=""admin"" path=""-1,1003,10032,100322,1003221"" isDoc="""">
<Doc id=""1003221"" parentID=""100322"" level=""4"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""0"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""1003-2-2-1"" writerName=""admin"" creatorName=""admin"" path=""-1,1003,10032,100322,1003221"" isDoc="""">
<content><![CDATA[]]></content>
</Doc>
<Doc id=""1003222"" parentID=""100322"" level=""4"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""2"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""1003-2-2-2"" writerName=""admin"" creatorName=""admin"" path=""-1,1003,10032,100322,1003222"" isDoc="""">
<Doc id=""1003222"" parentID=""100322"" level=""4"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""1"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""1003-2-2-2"" writerName=""admin"" creatorName=""admin"" path=""-1,1003,10032,100322,1003222"" isDoc="""">
<content><![CDATA[]]></content>
</Doc>
</Doc>
</Doc>
<Doc id=""10033"" parentID=""1003"" level=""2"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""3"" createDate=""2012-07-20T18:08:01"" updateDate=""2012-07-20T18:49:32"" nodeName=""Sub 2"" urlName=""1003-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1003,10033"" isDoc="""">
<Doc id=""10033"" parentID=""1003"" level=""2"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""2"" createDate=""2012-07-20T18:08:01"" updateDate=""2012-07-20T18:49:32"" nodeName=""Sub 2"" urlName=""1003-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1003,10033"" isDoc="""">
</Doc>
</Doc>
</root>";

View File

@@ -78,23 +78,6 @@ namespace Umbraco.Tests.Routing
}
}
//[TestCase(1046, "/home.aspx")]
//[TestCase(1173, "/home/sub1.aspx")]
//[TestCase(1174, "/home/sub1/sub2.aspx")]
//[TestCase(1176, "/home/sub1/sub-3.aspx")]
//[TestCase(1177, "/home/sub1/custom-sub-1.aspx")]
//[TestCase(1178, "/home/sub1/custom-sub-2.aspx")]
//[TestCase(1175, "/home/sub-2.aspx")]
//[TestCase(1172, "/test-page.aspx")]
//public void Get_Nice_Url_Not_Hiding_Top_Level_No_Directory_Urls(int nodeId, string niceUrlMatch)
//{
// var routingContext = GetRoutingContext("/test", 1111);
// var result = routingContext.NiceUrlProvider.GetNiceUrl(nodeId);
// Assert.AreEqual(niceUrlMatch, result);
//}
// test hideTopLevelNodeFromPath false
[TestCase(1046, "/home")]
[TestCase(1173, "/home/sub1")]
@@ -111,6 +94,7 @@ namespace Umbraco.Tests.Routing
ConfigurationManager.AppSettings.Set("umbracoUseDirectoryUrls", "true");
ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "false");
Umbraco.Core.Configuration.UmbracoSettings.UseDomainPrefixes = false;
var result = routingContext.NiceUrlProvider.GetNiceUrl(nodeId);
Assert.AreEqual(niceUrlMatch, result);
@@ -118,25 +102,6 @@ namespace Umbraco.Tests.Routing
// no need for umbracoUseDirectoryUrls test = should be handled by UriUtilityTests
//[TestCase(1046, "/")]
//[TestCase(1173, "/sub1.aspx")]
//[TestCase(1174, "/sub1/sub2.aspx")]
//[TestCase(1176, "/sub1/sub-3.aspx")]
//[TestCase(1177, "/sub1/custom-sub-1.aspx")]
//[TestCase(1178, "/sub1/custom-sub-2.aspx")]
//[TestCase(1175, "/sub-2.aspx")]
//[TestCase(1172, "/test-page.aspx")]
//public void Get_Nice_Url_Hiding_Top_Level_No_Directory_Urls(int nodeId, string niceUrlMatch)
//{
// var routingContext = GetRoutingContext("/test", 1111);
// ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "true");
// var result = routingContext.NiceUrlProvider.GetNiceUrl(nodeId);
// Assert.AreEqual(niceUrlMatch, result);
//}
// test hideTopLevelNodeFromPath true
[TestCase(1046, "/")]
[TestCase(1173, "/sub1")]
@@ -153,9 +118,46 @@ namespace Umbraco.Tests.Routing
ConfigurationManager.AppSettings.Set("umbracoUseDirectoryUrls", "true");
ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "true");
Umbraco.Core.Configuration.UmbracoSettings.UseDomainPrefixes = false;
var result = routingContext.NiceUrlProvider.GetNiceUrl(nodeId);
Assert.AreEqual(niceUrlMatch, result);
}
[Test]
public void Get_Nice_Url_Relative_Or_Absolute()
{
var routingContext = GetRoutingContext("http://example.com/test", 1111);
ConfigurationManager.AppSettings.Set("umbracoUseDirectoryUrls", "true");
ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "false");
Umbraco.Core.Configuration.UmbracoSettings.UseDomainPrefixes = false;
Assert.AreEqual("/home/sub1/custom-sub-1", routingContext.NiceUrlProvider.GetNiceUrl(1177));
Umbraco.Core.Configuration.UmbracoSettings.UseDomainPrefixes = true;
Assert.AreEqual("http://example.com/home/sub1/custom-sub-1", routingContext.NiceUrlProvider.GetNiceUrl(1177));
Umbraco.Core.Configuration.UmbracoSettings.UseDomainPrefixes = false;
routingContext.NiceUrlProvider.EnforceAbsoluteUrls = true;
Assert.AreEqual("http://example.com/home/sub1/custom-sub-1", routingContext.NiceUrlProvider.GetNiceUrl(1177));
}
[Test]
public void Get_Nice_Url_Unpublished()
{
var routingContext = GetRoutingContext("http://example.com/test", 1111);
ConfigurationManager.AppSettings.Set("umbracoUseDirectoryUrls", "true");
ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "false");
Umbraco.Core.Configuration.UmbracoSettings.UseDomainPrefixes = false;
Assert.AreEqual("#", routingContext.NiceUrlProvider.GetNiceUrl(999999));
Umbraco.Core.Configuration.UmbracoSettings.UseDomainPrefixes = true;
Assert.AreEqual("#", routingContext.NiceUrlProvider.GetNiceUrl(999999));
Umbraco.Core.Configuration.UmbracoSettings.UseDomainPrefixes = false;
routingContext.NiceUrlProvider.EnforceAbsoluteUrls = true;
Assert.AreEqual("#", routingContext.NiceUrlProvider.GetNiceUrl(999999));
}
}
}

View File

@@ -91,6 +91,22 @@ namespace Umbraco.Tests.Routing
Domain.MakeNew("http://domain3.com/fr", 10032, langFr.id);
}
void SetDomains5()
{
var langEn = Language.GetByCultureCode("en-US");
var langFr = Language.GetByCultureCode("fr-FR");
Domain.MakeNew("http://domain1.com/en", 10011, langEn.id);
Domain.MakeNew("http://domain1a.com/en", 10011, langEn.id);
Domain.MakeNew("http://domain1b.com/en", 10011, langEn.id);
Domain.MakeNew("http://domain1.com/fr", 10012, langFr.id);
Domain.MakeNew("http://domain1a.com/fr", 10012, langFr.id);
Domain.MakeNew("http://domain1b.com/fr", 10012, langFr.id);
Domain.MakeNew("http://domain3.com/en", 10031, langEn.id);
Domain.MakeNew("http://domain3.com/fr", 10032, langFr.id);
}
protected override string GetXmlContent(int templateId)
{
return @"<?xml version=""1.0"" encoding=""utf-8""?>
@@ -194,6 +210,7 @@ namespace Umbraco.Tests.Routing
ConfigurationManager.AppSettings.Set("umbracoUseDirectoryUrls", "true");
ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "false"); // ignored w/domains
Umbraco.Core.Configuration.UmbracoSettings.UseDomainPrefixes = false;
InitializeLanguagesAndDomains();
SetDomains1();
@@ -223,6 +240,7 @@ namespace Umbraco.Tests.Routing
ConfigurationManager.AppSettings.Set("umbracoUseDirectoryUrls", "true");
ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "false"); // ignored w/domains
Umbraco.Core.Configuration.UmbracoSettings.UseDomainPrefixes = false;
InitializeLanguagesAndDomains();
SetDomains2();
@@ -244,6 +262,7 @@ namespace Umbraco.Tests.Routing
ConfigurationManager.AppSettings.Set("umbracoUseDirectoryUrls", "true");
ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "false"); // ignored w/domains
Umbraco.Core.Configuration.UmbracoSettings.UseDomainPrefixes = false;
InitializeLanguagesAndDomains();
SetDomains3();
@@ -268,6 +287,7 @@ namespace Umbraco.Tests.Routing
public void Get_Nice_Url_NestedDomains(int nodeId, string currentUrl, bool absolute, string expected)
{
var routingContext = GetRoutingContext("/test", 1111);
Umbraco.Core.Configuration.UmbracoSettings.UseDomainPrefixes = false;
ConfigurationManager.AppSettings.Set("umbracoUseDirectoryUrls", "true");
ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "false"); // ignored w/domains
@@ -287,6 +307,7 @@ namespace Umbraco.Tests.Routing
ConfigurationManager.AppSettings.Set("umbracoUseDirectoryUrls", "true");
ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "false"); // ignored w/domains
Umbraco.Core.Configuration.UmbracoSettings.UseDomainPrefixes = false;
InitializeLanguagesAndDomains();
SetDomains4();
@@ -337,5 +358,52 @@ namespace Umbraco.Tests.Routing
Assert.IsTrue(ids.ContainsKey(route));
Assert.AreEqual(id, ids[route]);
}
[Test]
public void Get_Nice_Url_Relative_Or_Absolute()
{
var routingContext = GetRoutingContext("http://domain1.com/test", 1111);
ConfigurationManager.AppSettings.Set("umbracoUseDirectoryUrls", "true");
ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "false");
InitializeLanguagesAndDomains();
SetDomains4();
Umbraco.Core.Configuration.UmbracoSettings.UseDomainPrefixes = false;
Assert.AreEqual("/en/1001-1-1", routingContext.NiceUrlProvider.GetNiceUrl(100111));
Assert.AreEqual("http://domain3.com/en/1003-1-1", routingContext.NiceUrlProvider.GetNiceUrl(100311));
Umbraco.Core.Configuration.UmbracoSettings.UseDomainPrefixes = true;
Assert.AreEqual("http://domain1.com/en/1001-1-1", routingContext.NiceUrlProvider.GetNiceUrl(100111));
Assert.AreEqual("http://domain3.com/en/1003-1-1", routingContext.NiceUrlProvider.GetNiceUrl(100311));
Umbraco.Core.Configuration.UmbracoSettings.UseDomainPrefixes = false;
routingContext.NiceUrlProvider.EnforceAbsoluteUrls = true;
Assert.AreEqual("http://domain1.com/en/1001-1-1", routingContext.NiceUrlProvider.GetNiceUrl(100111));
Assert.AreEqual("http://domain3.com/en/1003-1-1", routingContext.NiceUrlProvider.GetNiceUrl(100311));
}
[Test]
public void Get_Nice_Url_Alternate()
{
var routingContext = GetRoutingContext("http://domain1.com/test", 1111);
ConfigurationManager.AppSettings.Set("umbracoUseDirectoryUrls", "true");
ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "false");
InitializeLanguagesAndDomains();
SetDomains5();
var result = routingContext.NiceUrlProvider.GetAllAbsoluteNiceUrls(100111);
// will always get absolute urls
// all of them
// including the local one - duplicate?! - then must manually exclude?
Assert.AreEqual(3, result.Count());
Assert.IsTrue(result.Contains("http://domain1.com/en/1001-1-1"));
Assert.IsTrue(result.Contains("http://domain1a.com/en/1001-1-1"));
Assert.IsTrue(result.Contains("http://domain1b.com/en/1001-1-1"));
}
}
}

View File

@@ -11,7 +11,7 @@ using umbraco.cms.businesslogic.template;
namespace Umbraco.Tests.Routing
{
[TestFixture]
[TestFixture(Ignore=true, IgnoreReason="Fails?")]
public class RenderRouteHandlerTests : BaseRoutingTest
{
@@ -19,6 +19,7 @@ namespace Umbraco.Tests.Routing
{
base.Initialize();
var webBoot = new WebBootManager(new UmbracoApplication());
//System.Configuration.ConfigurationManager.AppSettings.Set("umbracoPath", "???");
webBoot.CreateRoutes();
}

View File

@@ -55,6 +55,7 @@ namespace Umbraco.Tests.Routing
ConfigurationManager.AppSettings.Set("umbracoReservedUrls", "");
}
// do not test for /base here as it's handled before EnsureUmbracoRoutablePage is called
[TestCase("/umbraco_client/Tree/treeIcons.css", false)]
[TestCase("/umbraco_client/Tree/Themes/umbraco/style.css?cdv=37", false)]
[TestCase("/umbraco_client/scrollingmenu/style.css?cdv=37", false)]
@@ -65,7 +66,6 @@ namespace Umbraco.Tests.Routing
[TestCase("/install?installStep=license", false)]
[TestCase("/install/test.aspx", false)]
[TestCase("/config/splashes/noNodes.aspx", false)]
[TestCase("/base/somebasehandler", false)]
[TestCase("/", true)]
[TestCase("/home.aspx", true)]
[TestCase("/umbraco-test", true)]
@@ -74,7 +74,8 @@ namespace Umbraco.Tests.Routing
{
var httpContextFactory = new FakeHttpContextFactory(url);
var httpContext = httpContextFactory.HttpContext;
var umbracoContext = GetUmbracoContext(url, 1234);
var routingContext = GetRoutingContext(url);
var umbracoContext = routingContext.UmbracoContext;
var result = _module.EnsureUmbracoRoutablePage(umbracoContext, httpContext);

View File

@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Umbraco.Tests.TestHelpers;
using System.Configuration;
using Umbraco.Web.Routing;
namespace Umbraco.Tests.Routing
{
[TestFixture]
public class uQueryGetNodeIdByUrlTests : BaseRoutingTest
{
protected RoutingContext GetRoutingContext()
{
var url = "/test";
var templateId = 1111;
var lookup = new Umbraco.Web.Routing.LookupByNiceUrl();
var lookups = new Umbraco.Web.Routing.IDocumentLookup[] { lookup };
var umbracoContext = GetUmbracoContext(url, templateId, null);
var contentStore = new Umbraco.Web.DefaultPublishedContentStore();
var niceUrls = new NiceUrlProvider(contentStore, umbracoContext);
var routingContext = new RoutingContext(
umbracoContext,
lookups,
new Umbraco.Tests.Stubs.FakeLastChanceLookup(),
contentStore,
niceUrls);
//assign the routing context back to the umbraco context
umbracoContext.RoutingContext = routingContext;
return routingContext;
}
[TestCase(1046, "/home")]
[TestCase(1173, "/home/sub1")]
[TestCase(1174, "/home/sub1/sub2")]
[TestCase(1176, "/home/sub1/sub-3")]
[TestCase(1177, "/home/sub1/custom-sub-1")]
[TestCase(1178, "/home/sub1/custom-sub-2")]
[TestCase(1175, "/home/sub-2")]
[TestCase(1172, "/test-page")]
public void GetNodeIdByUrl_Not_Hiding_Top_Level(int nodeId, string url)
{
var routingContext = GetRoutingContext();
Umbraco.Web.UmbracoContext.Current = routingContext.UmbracoContext;
ConfigurationManager.AppSettings.Set("umbracoUseDirectoryUrls", "true");
ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "false");
Umbraco.Core.Configuration.UmbracoSettings.UseDomainPrefixes = false;
Assert.AreEqual(nodeId, global::umbraco.uQuery.GetNodeIdByUrl("http://example.com" + url));
}
}
}

View File

@@ -85,7 +85,7 @@ namespace Umbraco.Tests.TestHelpers
<!ATTLIST CustomDocument id ID #REQUIRED>
]>
<root id=""-1"">
<Home id=""1046"" parentID=""-1"" level=""1"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""2"" createDate=""2012-06-12T14:13:17"" updateDate=""2012-07-20T18:50:43"" nodeName=""Home"" urlName=""home"" writerName=""admin"" creatorName=""admin"" path=""-1,1046"" isDoc="""">
<Home id=""1046"" parentID=""-1"" level=""1"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""0"" createDate=""2012-06-12T14:13:17"" updateDate=""2012-07-20T18:50:43"" nodeName=""Home"" urlName=""home"" writerName=""admin"" creatorName=""admin"" path=""-1,1046"" isDoc="""">
<content><![CDATA[]]></content>
<umbracoUrlAlias><![CDATA[this/is/my/alias, anotheralias]]></umbracoUrlAlias>
<umbracoNaviHide>1</umbracoNaviHide>
@@ -106,7 +106,7 @@ namespace Umbraco.Tests.TestHelpers
<Home id=""1175"" parentID=""1046"" level=""2"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""" + templateId + @""" sortOrder=""2"" createDate=""2012-07-20T18:08:01"" updateDate=""2012-07-20T18:49:32"" nodeName=""Sub 2"" urlName=""sub-2"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1175"" isDoc=""""><content><![CDATA[]]></content>
</Home>
</Home>
<CustomDocument id=""1172"" parentID=""-1"" level=""1"" writerID=""0"" creatorID=""0"" nodeType=""1234"" template=""" + templateId + @""" sortOrder=""3"" createDate=""2012-07-16T15:26:59"" updateDate=""2012-07-18T14:23:35"" nodeName=""Test"" urlName=""test-page"" writerName=""admin"" creatorName=""admin"" path=""-1,1172"" isDoc="""" />
<CustomDocument id=""1172"" parentID=""-1"" level=""1"" writerID=""0"" creatorID=""0"" nodeType=""1234"" template=""" + templateId + @""" sortOrder=""1"" createDate=""2012-07-16T15:26:59"" updateDate=""2012-07-18T14:23:35"" nodeName=""Test"" urlName=""test-page"" writerName=""admin"" creatorName=""admin"" path=""-1,1172"" isDoc="""" />
</root>";
}

View File

@@ -71,6 +71,7 @@
<Compile Include="DataTypeFactoryTests.cs" />
<Compile Include="Routing\LookupByNiceUrlWithDomainsTests.cs" />
<Compile Include="Routing\NiceUrlsProviderWithDomainsTests.cs" />
<Compile Include="Routing\uQueryGetNodeIdByUrlTests.cs" />
<Compile Include="Surface\PluginControllerAreaTests.cs" />
<Compile Include="TestHelpers\BaseRoutingTest.cs" />
<Compile Include="GlobalSettingsTests.cs" />

View File

@@ -86,5 +86,37 @@ namespace Umbraco.Tests
{
return new Uri(url, url.StartsWith("http:") ? UriKind.Absolute : UriKind.Relative);
}
//
[TestCase("/", "/", "/")]
[TestCase("/", "/foo", "/foo")]
[TestCase("/", "~/foo", "/foo")]
[TestCase("/vdir", "/", "/vdir/")]
[TestCase("/vdir", "/foo", "/vdir/foo")]
[TestCase("/vdir", "/foo/", "/vdir/foo/")]
[TestCase("/vdir", "~/foo", "/vdir/foo")]
public void Uri_To_Absolute(string virtualPath, string sourceUrl, string expectedUrl)
{
UriUtility.SetAppDomainAppVirtualPath(virtualPath);
var resultUrl = UriUtility.ToAbsolute(sourceUrl);
Assert.AreEqual(expectedUrl, resultUrl);
}
//
[TestCase("/", "/", "/")]
[TestCase("/", "/foo", "/foo")]
[TestCase("/", "/foo/", "/foo/")]
[TestCase("/vdir", "/vdir", "/")]
[TestCase("/vdir", "/vdir/", "/")]
[TestCase("/vdir", "/vdir/foo", "/foo")]
[TestCase("/vdir", "/vdir/foo/", "/foo/")]
public void Url_To_App_Relative(string virtualPath, string sourceUrl, string expectedUrl)
{
UriUtility.SetAppDomainAppVirtualPath(virtualPath);
var resultUrl = UriUtility.ToAppRelative(sourceUrl);
Assert.AreEqual(expectedUrl, resultUrl);
}
}
}

View File

@@ -35,12 +35,12 @@
<BaseRestExtensions configSource="config\BaseRestExtensions.config" />
<appSettings>
<add key="umbracoDbDSN" value="server=.\sqlexpress;database=v4;user id=sa;password=test;Application Name=Umbraco41"/>
<add key="umbracoDbDSN" value="datalayer=SQLCE4Umbraco.SqlCEHelper,SQLCE4Umbraco;data source=|DataDirectory|\Umbraco.sdf"/>
<add key="umbracoConfigurationStatus" value="4.10.0"/>
<add key="umbracoReservedUrls" value="~/config/splashes/booting.aspx,~/install/default.aspx,~/config/splashes/noNodes.aspx,~/VSEnterpriseHelper.axd" />
<add key="umbracoReservedPaths" value="~/umbraco,~/install/" />
<add key="umbracoContentXML" value="~/App_Data/umbraco.config"/>
<add key="umbracoStorageDirectory" value="~/App_Data"/>
<add key="umbracoContentXML" value="~/App_Data/umbraco.config" />
<add key="umbracoStorageDirectory" value="~/App_Data" />
<add key="umbracoPath" value="~/umbraco" />
<add key="umbracoEnableStat" value="false" />
<add key="umbracoHideTopLevelNodeFromPath" value="true" />

View File

@@ -57,7 +57,7 @@
xsltSnippet = UmbEditor.IsSimpleEditor
? jQuery("#<%= editorSource.ClientID %>").getSelection().text
: UmbEditor._editor.selection();
: UmbEditor._editor.getSelection();
if (xsltSnippet == '') {
xsltSnippet = UmbEditor.IsSimpleEditor

View File

@@ -119,8 +119,8 @@ namespace Umbraco.Web
else
{
// if not in a domain - what is the default page?
// let's say it is the first one in the tree, if any
xpath = "(/root/*[@isDoc])[1]";
// let's say it is the first one in the tree, if any -- order by sortOrder
xpath = "/root/*[@isDoc and @sortOrder='0']";
}
}
else

View File

@@ -33,7 +33,7 @@ namespace Umbraco.Web.Routing
{
var pos = docRequest.Uri.AbsolutePath.LastIndexOf('/');
var templateAlias = docRequest.Uri.AbsolutePath.Substring(pos + 1);
path = path.Substring(0, pos);
path = pos == 0 ? "/" : path.Substring(0, pos);
//TODO: We need to check if the altTemplate is for MVC or not, though I'm not exactly sure how the best
// way to do that would be since the template is just an alias and if we are not having a flag on the

View File

@@ -18,7 +18,6 @@ namespace Umbraco.Web.Routing
/// </summary>
internal class NiceUrlProvider
{
internal const string NullUrl = "#";
/// <summary>
@@ -30,37 +29,56 @@ namespace Umbraco.Web.Routing
{
_umbracoContext = umbracoContext;
_publishedContentStore = publishedContentStore;
this.EnforceAbsoluteUrls = false;
}
private readonly UmbracoContext _umbracoContext;
private readonly IPublishedContentStore _publishedContentStore;
public bool EnforceAbsoluteUrls { get; set; }
#region GetNiceUrl
/// <summary>
/// Gets the nice url of a node.
/// </summary>
/// <param name="nodeId">The node id.</param>
/// <param name="nodeId">The node identifier.</param>
/// <returns>The nice url for the node.</returns>
/// <remarks>The url is absolute or relative depending on the current url.</remarks>
/// <remarks>The url is absolute or relative depending on the current url, settings, and options.</remarks>
public string GetNiceUrl(int nodeId)
{
return GetNiceUrl(nodeId, _umbracoContext.UmbracoUrl, false);
var absolute = UmbracoSettings.UseDomainPrefixes || this.EnforceAbsoluteUrls;
return GetNiceUrl(nodeId, _umbracoContext.UmbracoUrl, absolute);
}
/// <summary>
/// Gets the nice url of a node.
/// </summary>
/// <param name="nodeId">The node identifier.</param>
/// <param name="absolute">A value indicating whether the url should be absolute in any case.</param>
/// <returns>The nice url for the node.</returns>
/// <remarks>The url is absolute or relative depending on the current url, unless <c>absolute</c> is true, in which case the url is always absolute.</remarks>
public string GetNiceUrl(int nodeId, bool absolute)
{
return GetNiceUrl(nodeId, _umbracoContext.UmbracoUrl, absolute);
}
/// <summary>
/// Gets the nice url of a node.
/// </summary>
/// <param name="nodeId">The node id.</param>
/// <param name="current">The current url.</param>
/// <param name="current">The current absolute url.</param>
/// <param name="absolute">A value indicating whether the url should be absolute in any case.</param>
/// <returns>The nice url for the node.</returns>
/// <remarks>The url is absolute or relative depending on the current url, unless absolute is true, and then it is always absolute.</remarks>
/// <remarks>The url is absolute or relative depending on url indicated by <c>current</c>, unless <c>absolute</c> is true, in which case the url is always absolute.</remarks>
public string GetNiceUrl(int nodeId, Uri current, bool absolute)
{
Uri domainUri;
string path;
if (!current.IsAbsoluteUri)
throw new ArgumentException("Current url must be absolute.", "current");
// do not read cache if previewing
var route = _umbracoContext.InPreviewMode
? null
@@ -105,26 +123,7 @@ namespace Umbraco.Web.Routing
// no domain, respect HideTopLevelNodeFromPath for legacy purposes
if (domainUri == null && global::umbraco.GlobalSettings.HideTopLevelNodeFromPath)
{
// in theory if hideTopLevelNodeFromPath is true, then there should be only once
// top-level node, or else domains should be assigned. but for backward compatibility
// we add this check - we look for the document matching "/" and if it's not us, then
// we do not hide the top level path
// it has to be taken care of in IPublishedContentStore.GetDocumentByRoute too so if
// "/foo" fails (looking for "/*/foo") we try also "/foo".
// this does not make much sense anyway esp. if both "/foo/" and "/bar/foo" exist, but
// that's the way it works pre-4.10 and we try to be backward compat for the time being
if (node.Parent == null)
{
var rootNode = _publishedContentStore.GetDocumentByRoute(_umbracoContext, "/", true);
if (rootNode.Id == node.Id) // remove only if we're the default node
pathParts.RemoveAt(pathParts.Count - 1);
}
else
{
pathParts.RemoveAt(pathParts.Count - 1);
}
}
ApplyHideTopLevelNodeFromPath(node, pathParts);
// assemble the route
pathParts.Reverse();
@@ -140,6 +139,15 @@ namespace Umbraco.Web.Routing
return AssembleUrl(domainUri, path, current, absolute).ToString();
}
#endregion
#region GetAlternateNiceUrls
public IEnumerable<string> GetAllAbsoluteNiceUrls(int nodeId)
{
return GetAlternateNiceUrls(nodeId, _umbracoContext.UmbracoUrl);
}
/// <summary>
/// Gets the nice urls of a node.
/// </summary>
@@ -147,7 +155,7 @@ namespace Umbraco.Web.Routing
/// <param name="current">The current url.</param>
/// <returns>An enumeration of all valid urls for the node.</returns>
/// <remarks>The urls are absolute. A node can have more than one url if more than one domain is defined.</remarks>
public IEnumerable<string> GetNiceUrls(int nodeId, Uri current)
public IEnumerable<string> GetAlternateNiceUrls(int nodeId, Uri current)
{
// this is for editContent.aspx which had its own, highly buggy, implementation of NiceUrl...
//TODO: finalize & test implementation then replace in editContent.aspx
@@ -160,55 +168,77 @@ namespace Umbraco.Web.Routing
? null
: _umbracoContext.RoutesCache.GetRoute(nodeId);
if (route != null)
if (!string.IsNullOrEmpty(route))
{
// route is <id>/<path> eg "-1/", "-1/foo", "123/", "123/foo/bar"...
// there was a route in the cache - extract domainUri and path
// route is /<path> or <domainRootId>/<path>
int pos = route.IndexOf('/');
path = route.Substring(pos);
int id = int.Parse(route.Substring(0, pos)); // will be -1 or 1234
domainUris = id > 0 ? DomainUrisAtNode(id, current) : new Uri[] { };
path = pos == 0 ? route : route.Substring(pos);
domainUris = pos == 0 ? new Uri[] { } : DomainUrisAtNode(int.Parse(route.Substring(0, pos)), current);
}
else
{
// there was no route in the cache - create a route
var node = _publishedContentStore.GetDocumentById(_umbracoContext, nodeId);
if (node == null)
return new string[] { NullUrl }; // legacy wrote to the log here...
var pathParts = new List<string>();
int id = nodeId;
domainUris = DomainUrisAtNode(id, current);
while (!domainUris.Any() && id > 0)
{
LogHelper.Warn<NiceUrlProvider>(
"Couldn't find any page with nodeId={0}. This is most likely caused by the page not being published.",
nodeId);
return new string[] { NullUrl };
}
// walk up from that node until we hit a node with domains,
// or we reach the content root, collecting urls in the way
var pathParts = new List<string>();
var n = node;
domainUris = DomainUrisAtNode(n.Id, current);
while (!domainUris.Any() && n != null) // n is null at root
{
// get the url
var urlName = node.UrlName;
pathParts.Add(urlName);
node = node.Parent; //set to parent node
id = node.Id;
domainUris = id > 0 ? DomainUrisAtNode(id, current) : new Uri[] { };
// move to parent node
n = n.Parent;
domainUris = n == null ? new Uri[] { } : DomainUrisAtNode(n.Id, current);
}
// no domain, respect HideTopLevelNodeFromPath for legacy purposes
if (!domainUris.Any() && global::umbraco.GlobalSettings.HideTopLevelNodeFromPath)
pathParts.RemoveAt(pathParts.Count - 1);
ApplyHideTopLevelNodeFromPath(node, pathParts);
// assemble the route
pathParts.Reverse();
path = "/" + string.Join("/", pathParts); // will be "/" or "/foo" or "/foo/bar" etc
route = id.ToString() + path;
route = (n == null ? "" : n.Id.ToString()) + path;
// do not store if previewing
if (!_umbracoContext.InPreviewMode)
_umbracoContext.RoutesCache.Store(nodeId, route);
}
// assemble the alternate urls from domainUris (maybe empty) and path
return AssembleUrls(domainUris, path, current).Select(uri => uri.ToString());
}
#endregion
#region Utilities
Uri AssembleUrl(Uri domainUri, string path, Uri current, bool absolute)
{
Uri uri;
if (domainUri == null)
{
// no domain was found : return a relative url, add vdir if any
uri = new Uri(SystemDirectories.Root + path, UriKind.Relative);
// no domain was found : return an absolute or relative url
// handle vdir if any
if (!absolute || current == null)
uri = new Uri(UriUtility.ToAbsolute(path), UriKind.Relative);
else
uri = new Uri(current.GetLeftPart(UriPartial.Authority) + UriUtility.ToAbsolute(path));
}
else
{
@@ -229,17 +259,26 @@ namespace Umbraco.Web.Routing
return path == "/" ? path : path.TrimEnd('/');
}
// always build absolute urls unless we really cannot
IEnumerable<Uri> AssembleUrls(IEnumerable<Uri> domainUris, string path, Uri current)
{
if (domainUris.Any())
List<Uri> uris = new List<Uri>();
if (!domainUris.Any())
{
return domainUris.Select(domainUri => new Uri(domainUri.GetLeftPart(UriPartial.Path).TrimEnd('/') + path));
// no domain was found : return an absolute or relative url
// handle vdir if any
if (current == null)
uris.Add(new Uri(UriUtility.ToAbsolute(path), UriKind.Relative));
else
uris.Add(new Uri(current.GetLeftPart(UriPartial.Authority) + UriUtility.ToAbsolute(path)));
}
else
{
// no domain was found : return a relative url, add vdir if any
return new Uri[] { new Uri(SystemDirectories.Root + path, UriKind.Relative) };
// domains were found : return -- FIXME?
uris.AddRange(domainUris.Select(domainUri => new Uri(domainUri.GetLeftPart(UriPartial.Path).TrimEnd('/') + path)));
}
return uris.Select(uri => UriUtility.UriFromUmbraco(uri));
}
Uri DomainUriAtNode(int nodeId, Uri current)
@@ -263,6 +302,28 @@ namespace Umbraco.Web.Routing
return domainAndUris.Select(d => d.Uri);
}
void ApplyHideTopLevelNodeFromPath(Core.Models.IDocument node, List<string> pathParts)
{
// in theory if hideTopLevelNodeFromPath is true, then there should be only once
// top-level node, or else domains should be assigned. but for backward compatibility
// we add this check - we look for the document matching "/" and if it's not us, then
// we do not hide the top level path
// it has to be taken care of in IPublishedContentStore.GetDocumentByRoute too so if
// "/foo" fails (looking for "/*/foo") we try also "/foo".
// this does not make much sense anyway esp. if both "/foo/" and "/bar/foo" exist, but
// that's the way it works pre-4.10 and we try to be backward compat for the time being
if (node.Parent == null)
{
var rootNode = _publishedContentStore.GetDocumentByRoute(_umbracoContext, "/", true);
if (rootNode.Id == node.Id) // remove only if we're the default node
pathParts.RemoveAt(pathParts.Count - 1);
}
else
{
pathParts.RemoveAt(pathParts.Count - 1);
}
}
#endregion
}
}

View File

@@ -323,7 +323,7 @@ namespace Umbraco.Web
public string NiceUrlWithDomain(int nodeId)
{
var niceUrlsProvider = UmbracoContext.Current.NiceUrlProvider;
return niceUrlsProvider.GetNiceUrl(nodeId, UmbracoContext.Current.UmbracoUrl, true);
return niceUrlsProvider.GetNiceUrl(nodeId, true);
}
#endregion

View File

@@ -222,7 +222,7 @@ namespace Umbraco.Web
if (!EnsureIsConfigured(httpContext, uri))
return false;
// ensure Umbraco has documents to serve
if (!EnsureHasContent(httpContext))
if (!EnsureHasContent(context, httpContext))
return false;
return true;
@@ -316,9 +316,8 @@ namespace Umbraco.Web
// ensures Umbraco has at least one published node
// if not, rewrites to splash and return false
// if yes, return true
bool EnsureHasContent(HttpContextBase httpContext)
bool EnsureHasContent(UmbracoContext context, HttpContextBase httpContext)
{
var context = UmbracoContext.Current;
var store = context.RoutingContext.PublishedContentStore;
if (!store.HasContent(context))
{

View File

@@ -7,47 +7,58 @@ using umbraco;
namespace Umbraco.Web
{
static class UriUtility
public static class UriUtility
{
static readonly string _appVirtualPath;
static readonly string _appVirtualPathPrefix;
static string _appPath;
static string _appPathPrefix;
static UriUtility()
{
// Virtual path
_appVirtualPath = HttpRuntime.AppDomainAppVirtualPath ?? "/";
_appVirtualPathPrefix = _appVirtualPath;
if (_appVirtualPathPrefix == "/")
_appVirtualPathPrefix = String.Empty;
SetAppDomainAppVirtualPath(HttpRuntime.AppDomainAppVirtualPath);
}
// internal for unit testing only
internal static void SetAppDomainAppVirtualPath(string appPath)
{
_appPath = appPath ?? "/";
_appPathPrefix = _appPath;
if (_appPathPrefix == "/")
_appPathPrefix = String.Empty;
}
// will be "/" or "/foo"
public static string AppVirtualPath
public static string AppPath
{
get { return _appVirtualPath; }
get { return _appPath; }
}
// will be "" or "/foo"
public static string AppVirtualPathPrefix
public static string AppPathPrefix
{
get { return _appVirtualPathPrefix; }
get { return _appPathPrefix; }
}
public static string ToAbsolute(string url)
// adds the virtual directory if any
// see also VirtualPathUtility.ToAbsolute
// FIXME
public static string ToAbsolute(string url)
{
return ResolveUrl(url);
//return ResolveUrl(url);
url = url.TrimStart('~');
return _appPathPrefix + url;
}
public static string ToAppRelative(string url)
// strips the virtual directory if any
// see also VirtualPathUtility.ToAppRelative
public static string ToAppRelative(string virtualPath)
{
if (url.StartsWith(_appVirtualPathPrefix))
url = url.Substring(_appVirtualPathPrefix.Length);
return url;
if (virtualPath.StartsWith(_appPathPrefix))
virtualPath = virtualPath.Substring(_appPathPrefix.Length);
return virtualPath;
}
// fixme - what about vdir?
// path = path.Substring(UriUtility.AppVirtualPathPrefix.Length); // remove virtual directory
// maps an internal umbraco uri to a public uri
// ie with virtual directory, .aspx if required...
public static Uri UriFromUmbraco(Uri uri)
{
var path = uri.GetSafeAbsolutePath();
@@ -59,19 +70,19 @@ namespace Umbraco.Web
else if (UmbracoSettings.AddTrailingSlash)
path += "/";
path = ToAbsolute(path);
return uri.Rewrite(path);
}
/// <summary>
/// Converts a Uri to a path based URI that is lower cased
/// </summary>
/// <param name="uri"></param>
/// <returns></returns>
public static Uri UriToUmbraco(Uri uri)
// maps a public uri to an internal umbraco uri
// ie no virtual directory, no .aspx, lowercase...
public static Uri UriToUmbraco(Uri uri)
{
var path = uri.GetSafeAbsolutePath();
path = path.ToLower();
path = ToAppRelative(path); // strip vdir if any
//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
@@ -116,7 +127,7 @@ namespace Umbraco.Web
}
StringBuilder sbUrl = new StringBuilder();
sbUrl.Append(HttpRuntime.AppDomainAppVirtualPath);
sbUrl.Append(_appPathPrefix);
if (sbUrl.Length == 0 || sbUrl[sbUrl.Length - 1] != '/') sbUrl.Append('/');
// found question mark already? query string, do not touch!

View File

@@ -20,6 +20,7 @@ using umbraco.cms.businesslogic.web;
using umbraco.presentation;
using umbraco.cms.businesslogic.skinning;
using System.Collections.Generic;
using System.Linq;
namespace umbraco.cms.presentation
{
@@ -180,7 +181,7 @@ namespace umbraco.cms.presentation
publishProps.addProperty(ui.Text("content", "expireDate", base.getUser()), dpExpire);
// url's
updateLinks();
UpdateNiceUrls();
linkProps.addProperty(ui.Text("content", "urls", base.getUser()), l);
if (domainText.Text != "")
@@ -323,7 +324,7 @@ namespace umbraco.cms.presentation
UnPublish.Visible = true;
_documentHasPublishedVersion = _document.HasPublishedVersion();
updateLinks();
UpdateNiceUrls();
}
else
{
@@ -353,57 +354,36 @@ namespace umbraco.cms.presentation
}
private void updateLinks()
{
if (_documentHasPublishedVersion)
{
// zb-00007 #29928 : refactor
string currentLink = library.NiceUrl(_document.Id);
l.Text = "<a href=\"" + currentLink + "\" target=\"_blank\">" + currentLink + "</a>";
void UpdateNiceUrls()
{
if (!_documentHasPublishedVersion)
{
l.Text = "<i>" + ui.Text("content", "itemNotPublished", base.getUser()) + "</i>";
return;
}
// domains
domainText.Text = "";
foreach (string s in _document.Path.Split(','))
{
if (int.Parse(s) > -1)
{
cms.businesslogic.web.Document dChild = new cms.businesslogic.web.Document(int.Parse(s));
if (dChild.Published)
{
cms.businesslogic.web.Domain[] domains = cms.businesslogic.web.Domain.GetDomainsById(int.Parse(s));
if (domains.Length > 0)
{
for (int i = 0; i < domains.Length; i++)
{
string tempLink = "";
if (library.NiceUrl(int.Parse(s)) == "")
tempLink = "<em>N/A</em>";
else if (int.Parse(s) != _document.Id)
{
string tempNiceUrl = library.NiceUrl(int.Parse(s));
var niceUrlProvider = Umbraco.Web.UmbracoContext.Current.RoutingContext.NiceUrlProvider;
var url = niceUrlProvider.GetNiceUrl(_document.Id);
string niceUrl = tempNiceUrl != "/" ? currentLink.Replace(tempNiceUrl.Replace(".aspx", ""), "") : currentLink;
if (!niceUrl.StartsWith("/"))
niceUrl = "/" + niceUrl;
if (url == "#")
{
var parent = _document;
while (parent.Published && parent.ParentId > 0)
parent = new Document(_document.ParentId);
if (parent.Published)
l.Text = "<i>" + ui.Text("content", "parentNotPublished", "???", base.getUser()) + "</i>";
else
l.Text = "<i>" + ui.Text("content", "parentNotPublished", parent.Text, base.getUser()) + "</i>";
return;
}
tempLink = "http://" + domains[i].Name + niceUrl;
}
else
tempLink = "http://" + domains[i].Name;
l.Text = string.Format("<a href=\"{0}\" target=\"_blank\">{0}</a>", url);
domainText.Text += "<a href=\"" + tempLink + "\" target=\"_blank\">" + tempLink + "</a><br/>";
}
}
}
else
l.Text = "<i>" + ui.Text("content", "parentNotPublished", dChild.Text, base.getUser()) + "</i>";
}
}
}
else
l.Text = "<i>" + ui.Text("content", "itemNotPublished", base.getUser()) + "</i>";
}
var lb = new System.Text.StringBuilder();
foreach (var altUrl in niceUrlProvider.GetAllAbsoluteNiceUrls(_document.Id).Where(u => u != url))
lb.AppendFormat("<a href=\"{0}\" target=\"_blank\">{0}</a><br />", altUrl);
domainText.Text = lb.ToString();
}
/// <summary>
/// Clears the page of all controls and shows a simple message. Used if users don't have visible access to the page.

View File

@@ -200,21 +200,14 @@ namespace umbraco
/// </remarks>
public static int GetNodeIdByUrl(string url)
{
var xpathQuery = GetXPathQuery(url);
var xmlNode = content.Instance.XmlContent.SelectSingleNode(xpathQuery);
var uri = new System.Uri(url);
uri = Umbraco.Web.UriUtility.UriToUmbraco(uri);
if (xmlNode != null && xmlNode.Attributes.Count > 0)
{
int nodeId;
var id = xmlNode.Attributes.GetNamedItem("id").Value;
if (int.TryParse(id, out nodeId))
{
return nodeId;
}
}
return uQuery.RootNodeId;
var docreq = new Umbraco.Web.Routing.DocumentRequest(uri, Umbraco.Web.UmbracoContext.Current.RoutingContext);
var builder = new Umbraco.Web.Routing.DocumentRequestBuilder(docreq);
builder.LookupDomain();
builder.LookupDocument();
return docreq.HasNode ? docreq.DocumentId : uQuery.RootNodeId;
}
/// <summary>
@@ -357,21 +350,5 @@ namespace umbraco
return dictionary;
}
/// <summary>
/// Gets the XPath query.
/// </summary>
/// <param name="url">The specified URL.</param>
/// <returns>
/// Returns an XPath query for the specified URL.
/// </returns>
private static string GetXPathQuery(string url)
{
// strip the ASP.NET file-extension from the URL.
url = url.Replace(".aspx", string.Empty);
// return the XPath query.
return requestHandler.CreateXPathQuery(url, true);
}
}
}