What version of Umbraco are you using? The Node class was deprecated a long time ago.
In Umbraco 7 you should use Umbraco.TypeContent(node.Id) to get an instance of a node and then you can use the extension vNode.UrlAbsolute() to get the full, absolute URL.
Your intermittent issue, though, may well be because of the lag between a page being published (ie. appearing in the database as published content) and the time it takes to actually generate the XML and refresh the cache. Umbraco uses the XML cache to get Published Content items - if the XML hasn't been generated and the cache updated in time then it won't have a URL.
If you were in a template or a class inheriting from a special Umbraco base class (eg SurfaceController, RenderMvcController) you would have access to the Umbraco Helpers that Dan is describing via
Umbraco.
but as you are writing code in an application event handler you would need to create your own new Umbraco Helper instance:
var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
foreach (var node in args.PublishedEntities)
{
var publishedContent = umbracoHelper.TypedContent(node.Id);
var strUrl = publishedContent.Url;
Problem using NiceUrl
When a page is published, I'm using contentServicePublish.cs to send an email to a distribution list.
In the email, I want to give a link back to the page that was updated when it was published.
In contentServicePublish.cs, I'm getting the node of the page as follows:
And then put the link to the page in the email:
This works most of the time but intermittently fails. When it does fail, the HTML in the email source is:
What am I doing wrong here?
Your help would be much appreciated.
Thanking you in anticipation.
Roger
What version of Umbraco are you using? The
Node
class was deprecated a long time ago.In Umbraco 7 you should use
Umbraco.TypeContent(node.Id)
to get an instance of a node and then you can use the extensionvNode.UrlAbsolute()
to get the full, absolute URL.Your intermittent issue, though, may well be because of the lag between a page being published (ie. appearing in the database as published content) and the time it takes to actually generate the XML and refresh the cache. Umbraco uses the XML cache to get Published Content items - if the XML hasn't been generated and the cache updated in time then it won't have a URL.
Thanks, Dan.
As a newbie, I'm being a bit dumb but Umbraco.TypeContent(node.Id) is not available on the page.
What am I doing wrong?
Hi Roger
If you were in a template or a class inheriting from a special Umbraco base class (eg SurfaceController, RenderMvcController) you would have access to the Umbraco Helpers that Dan is describing via
but as you are writing code in an application event handler you would need to create your own new Umbraco Helper instance:
regards
Marc
Thanks, Marc.
Used the code as you suggested. Now waiting to see if the intermittent problem, described in the initial post, has been fixed.
is working on a reply...