假设你有一把umbraco安装有两个网站各自的主页和页面,如
可以与
Node currentHome = new Node(int.Parse(currentNode.Path.Split(',')[1]));
找到现在, currentNode.Path
返回以-1开头的以逗号分隔的整数的字符串, 即根,即所谓的主根,在其下所有主页'生活'。
E.g.页面2.1的路径的值为“-1,1002,1003”。当用逗号分割时,最终会得到一个包含索引为0,1,2的3个元素的数组。现在,第二个,索引1将给出主节点的id。正如你所看到的,最后一个id是当前节点的id。另外,这些索引还会告诉节点的级别,因此主页的级别为1.
我在Intranet/Extranet上使用并具有受保护页面的模板上使用了以下脚本。当访问者访问受保护页面的链接时,他/她被拒绝访问并重定向到具有成员登录名的主页。
<%@ Master Language="C#" MasterPageFile="~/umbraco/masterpages/default.master" AutoEventWireup="true" %>
<%@ Import Namespace="umbraco.NodeFactory" %>
<script runat="server" language="CSharp">
protected void Page_Load(object sender, EventArgs e)
{
// prevents template to be run without proper authorisation
Node currentNode = Node.GetCurrent();
Node currentHome = new Node(int.Parse(currentNode.Path.Split(',')[1]));
Boolean HasAccess = umbraco.library.HasAccess(currentNode.Id, currentNode.Path);
Boolean IsProtected = umbraco.library.IsProtected(currentNode.Id, currentNode.Path);
if (IsProtected && !HasAccess)
{
// redirect to ancestor-or-self::HomePage
Response.Status = "403 Forbidden";
Response.Redirect(umbraco.library.NiceUrl(currentHome.Id), true);
}
}
</script>
<asp:Content ContentPlaceHolderID="ContentPlaceHolderDefault" runat="server">
<!-- redirect to home page -->
</asp:Content>
嗨,谢谢你的回复!对于Umbraco来说是相当新颖的事情,需要一段时间才能理解很多细节部分......所以没有想到向上遍历一个特定的节点类型..我猜测会是这种情况..不幸的是,我是不使用Razor页面..实际上,我有一个ASHX页面,它调用一些后端代码来计算逻辑内容(使用Umbraco API调用),然后ASHX页面将输出作为JSON提供给Umbraco中托管的纯HTML/JS页面模板。 我会检查其他链接 - 但你的意见至少给了我这个想法谢谢 –