sitecore通过客户端url查询项目

标签 sitecore sitecore6

我正在寻找一种快速而肮脏的方法来通过友好的网址查询特定页面的布局文件。这可能很简单,但我找不到解决方案。

基本上我想说的是以下内容。伪代码:

var mainpage = Sitecore.EasyQueryUtility.GetItemByFriendlyUrl(requestedUrl);

var mainpage = Sitecore.EasyQueryUtility.GetOppositeOfFriendlyUrl(friendlyurl);

最佳答案

听起来您想在这里做两件事:

  1. 根据地址栏中呈现的网址(即友好网址)确定项目
  2. 确定项目后,再确定该项目所使用的布局。

如果这些是正确的,希望这可以帮助您:

注意:我即时执行的未经测试的代码

// if you have the full URL with protocol and host
public static Item GetItemFromUrl(string url)
{
    string path = new Uri(url).PathAndQuery;    
    return GetItemFromPath(path);
}

// if you have just the path after the hostname
public static Item GetItemFromPath(string path)
{
    // remove query string
    if(path.Contains("?"))
        path = path.split('?')[0];

    path = path.Replace(".aspx", "");

    return Sitecore.Context.Database.GetItem(path);
}

一旦获得该项目,您就可以获取布局的名称,如下所示:

item.Visualization.GetLayout(Sitecore.Context.Device).Name;

或者布局到 ASPX 的物理文件路径:

item.Visualization.GetLayout(Sitecore.Context.Device).FilePath;

关于sitecore通过客户端url查询项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9401593/

相关文章:

sitecore - 使用动态选项卡在单页上处理多个 WFFM 表单

c# - MvcBuildViews 忽略 ascx 和 aspx,只编译 cshtml

c# - 将 NVelocity 与 Sitecore FieldRenderer 结合使用

sitecore - 从另一个分支获取 Sitecore sibling

c# - Sitecore 子项目排序问题

每当添加一个项目时,Sitecore 都会添加几个孤立项目

c# - Sitecore - 在 C# 中设置控件顺序

Sitecore 软件包安装永无止境

sitecore - 如何在重建过程中保持Lucene索引的可用性?

sitecore - 如何获取 Sitecore 项目的域名