Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hey
I'm trying to make a check that looks at a page when it's published to check if a given UmbracoUrlAlias already exisits.
But when I check the value on the published node, the value is null...
My function:
private void ContentService_Publishing(IContentService sender, ContentPublishingEventArgs e) { foreach (var node in e.PublishedEntities) { using (UmbracoContextReference contextReference = _umbracoContext.EnsureUmbracoContext()) { UmbracoContext context = contextReference.UmbracoContext; IPublishedContent content = context.Content.GetById(node.Id); var altUrl = node.GetValue<string>("umbracoUrlAlias"); if (!string.IsNullOrEmpty(altUrl) & altUrl != null) { var roots = context.Content.GetAtRoot(); foreach (var root in roots) { var UrlAliasExists = root.DescendantsOrSelf().Where(x => x.Id != node.Id && altUrl.ToString() == x.Value<string>("umbracoUrlAlias")).ToList(); //var UrlAliasExists = root.Descendants().Where(x => x.Id != node.Id && altUrl.ToString() == x.Value<string>("umbracoUrlAlias")).ToList(); if (UrlAliasExists.Any()) { e.Cancel = true; e.Messages.Add(new Umbraco.Core.Events.EventMessage("fejl i url alias", string.Format("alias [{0}] der er valgt bruges allerede", node.GetValue("umbracourlalias")), Umbraco.Core.Events.EventMessageType.Error)); } } } } } }
My variable "altUrl" are always null... ?
Have tried: - node.GetValue
Anyone that can see what i'm doing wrong ?
Version: Umbraco 8.6.3
You try get IPublishedContent from new element what not published or not saved yet
try hey value from node
node.GetValue("umbracoUrlAlias")
I'm also doing that.
var altUrl = node.GetValue<string>("umbracoUrlAlias");
But it's always null ?...
may be you have variants enabled? if yes you need check property by culture too
var altUrl = node.GetValue<string>("umbracoUrlAlias","<CULTURE>");
I think that did it.. Makes it a litte more bigger to check on each culture node has UmbracoUrlAlias that matches another one..
Why is I possible to have the samme UmbracoUrlAlias on diffrent nodes... ?
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
Check UmbracoUrlAlias existis
Hey
I'm trying to make a check that looks at a page when it's published to check if a given UmbracoUrlAlias already exisits.
But when I check the value on the published node, the value is null...
My function:
My variable "altUrl" are always null... ?
Have tried: - node.GetValue
Anyone that can see what i'm doing wrong ?
Version: Umbraco 8.6.3
You try get IPublishedContent from new element what not published or not saved yet
try hey value from node
Hey
I'm also doing that.
But it's always null ?...
may be you have variants enabled? if yes you need check property by culture too
I think that did it.. Makes it a litte more bigger to check on each culture node has UmbracoUrlAlias that matches another one..
Why is I possible to have the samme UmbracoUrlAlias on diffrent nodes... ?
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.