Files
Umbraco-CMS/src/Umbraco.Web/Routing/ResolveById.cs

50 lines
1.4 KiB
C#
Raw Normal View History

using System;
using System.Diagnostics;
using System.Xml;
2012-07-26 07:52:13 -02:00
using Umbraco.Core.Resolving;
namespace Umbraco.Web.Routing
{
// handles /1234 where 1234 is the id of a document
//
2012-07-26 07:52:13 -02:00
[ResolutionWeight(20)]
2012-07-22 14:01:18 -02:00
internal class ResolveById : IRequestDocumentResolver
{
2012-07-22 14:01:18 -02:00
static readonly TraceSource Trace = new TraceSource("ResolveById");
2012-07-22 14:01:18 -02:00
public bool TrySetDocument(DocumentRequest docreq)
{
XmlNode node = null;
int nodeId = -1;
2012-07-20 18:54:59 -02:00
if (docreq.Uri.AbsolutePath != "/") // no id if "/"
{
2012-07-20 18:54:59 -02:00
string noSlashPath = docreq.Uri.AbsolutePath.Substring(1);
if (!Int32.TryParse(noSlashPath, out nodeId))
nodeId = -1;
if (nodeId > 0)
{
Trace.TraceInformation("Id={0}", nodeId);
node = docreq.RoutingContext.ContentStore.GetNodeById(nodeId);
if (node != null)
{
docreq.Node = node;
Trace.TraceInformation("Found node with id={0}", docreq.NodeId);
}
else
{
nodeId = -1; // trigger message below
}
}
}
if (nodeId == -1)
Trace.TraceInformation("Not a node id");
return node != null;
}
}
}