如何从Umbraco中的url中删除节点ID和扩展名

时间:2014-01-08 11:32:31

标签: umbraco

现在我正在开发一个项目,我必须在其中显示带有url选择器数据类型的标题导航,因为我有两个字段:Text(Text String)&链接(Url Picker)。

要获得此导航链接,我已完成以下代码:

Default.aspx的

 <asp:Repeater ID="rptMainNavListing" runat="server" OnItemDataBound="rptMainNavListing_OnItemDataBound">
                <HeaderTemplate>
                    <div class="header_top_links_right">
                        <ul>
                </HeaderTemplate>
                <ItemTemplate>
                    <li>
                        <asp:HyperLink ID="hlLink" runat="server">
                        </asp:HyperLink>
                        <asp:Literal ID="ltText" runat="server"></asp:Literal>
                    </li>
                </ItemTemplate>
                <FooterTemplate>
                    </ul>
                         </div>
                </FooterTemplate>
            </asp:Repeater>

Default.aspx.cs

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Reshape.Framework;
using Reshape.Framework.UI;
using Reshape.Framework.Constants;
using umbraco.NodeFactory;

namespace Reshape.UserControls {
    public partial class Header : BaseLayout {
        protected void Page_Load(object sender, EventArgs e) {
            if (!IsPostBack) {
                Node currentNode = Common.GetMainNavigationFolder();
                var childList = currentNode.Children;
                rptMainNavListing.DataSource = currentNode.Children;
                rptMainNavListing.DataBind();
        }
        }

        protected void rptMainNavListing_OnItemDataBound(object sender, RepeaterItemEventArgs e) {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) {
                Node itm = e.Item.DataItem as Node;
                if (itm != null) {
                    Literal ltText = (Literal)e.Item.FindControl("ltText");
                    HyperLink hlLink = e.Item.FindControl("hlLink") as HyperLink;
                    if (ltText != null) {
                        ltText.Text = itm.GetProperty("text").Value;
                    }
                    if (hlLink != null) {
                        hlLink.NavigateUrl = itm.Url;
                        hlLink.Text = itm.GetProperty("link").Value;
                    }
                }
            }
        }
    }
}

调试完这段代码后,我得到了以下格式的url(带id和扩展名)

False1154/regions.aspxRegions 
here id =False1154
extension =regions.aspx

我希望网址只有“区域”。

2 个答案:

答案 0 :(得分:0)

在web.config中,将umbracoUseDirectoryUrls值设置为true。

这里有一些 - 相当过时 - 文档:http://our.umbraco.org/wiki/install-and-setup/setting-up-umbraco-for-friendly-urls

答案 1 :(得分:0)

将您的代码更改为以下代码....您将解决此问题: - )

if (childList.Count > 0) {
                    rptMainNavListing.DataSource = childList; ;
                    rptMainNavListing.DataBind();

                }

转发器代码

  protected void rptMainNavListing_OnItemDataBound(object sender, RepeaterItemEventArgs e) {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) {
                Node itm = e.Item.DataItem as Node;
                if (itm != null) {
                    Literal ltText = (Literal)e.Item.FindControl("ltText");
                    HyperLink hlLink = e.Item.FindControl("hlLink") as HyperLink;
                    if (itm.GetProperty(FieldName.LINK) != null && !string.IsNullOrEmpty(itm.GetProperty(FieldName.LINK).Value)) {
                        hlLink.NavigateUrl = umbraco.library.NiceUrl(Convert.ToInt16(itm.GetProperty(FieldName.LINK).Value));
                    }
                    hlLink.Text = itm.GetProperty(FieldName.TEXT).Value;
                }
            }
        }