c# - Umbraco 自定义 url 段

标签 c# asp.net umbraco

我需要在每次用户创建新节点时生成自定义 url slug,或者(如果可能)完全停止 Umbraco 使用 umbraco.library:NiceUrl 方法。

最佳答案

在我的回复中,我假设您使用的是 Umbraco v4.7.x。

首先,我会确保您的节点具有 umbracoUrlName它们的文档类型属性和/或 umbracoUrlAlias属性(我将留给您来决定哪个最适合您的要求)。

然后您可以订阅 Document.New 事件处理程序。要订阅 Document.New 处理程序,您需要从 ApplicationBase 类继承,请参见以下示例:

public class ApplicationBase : umbraco.BusinessLogic.ApplicationBase
{
    /// <summary>
    /// Initializes a new instance of the <see cref="ApplicationBase"/> class.
    /// </summary>
    public ApplicationBase()
    {
        Document.New += this.Document_New;
    }

    private void Document_New(Document sender, NewEventArgs e)
    {
        sender.getProperty("umbracoUrlName").Value = "your_urlname_here";
        sender.Save();
    }    
}

关于c# - Umbraco 自定义 url 段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8427935/

相关文章:

c# - 使用SQL返回JSON字符串

asp.net - 使用 NUnit、NSubstitute 和异步方法进行单元测试时出现 NullReferenceException

asp.net - 使用 asp.net 验证器控件与 JQuery 进行前端验证有什么区别

asp.net - 什么是流动布局?

asp.net - 从 umbraco 搜索中排除节点

asp.net - 无法加载 View 状态。正在加载 View 状态的控制树

c# - 使用界面与具体 map 的 AutoMapper 映射

c# - 如何对 FileStream 的 File.Open 进行单元测试

azure - Windows Azure 上的 Umbraco 6.05

c# - 响应始终为 null