I need to generate a custom url slug each time the user creates a new node, or (if possible) stop Umbraco completely from using the umbraco.library:NiceUrl method.
2
votes
1 Answers
1
votes
In my response I'm assuming you are using Umbraco v4.7.x.
First of all I would ensure that your nodes have the umbracoUrlName document type property on them and/or the umbracoUrlAlias property (I will leave it you to decide which best suits your requirements).
You can then subscribe to the Document.New event handler. To subscribe to the Document.New handler you will need to inherit from the ApplicationBase class, see the following example:
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();
}
}