I'm using version 7.1.4 and I'm trying to write some code that will get the Not Found Page Id from UmbracoSettings.config: <error404>2172</error404>
In earlier versions, I would use umbraco.library.GetCurrentNotFoundPageId() but that does not work any more. (umbraco.library' does not contain a definition for 'GetCurrentNotFoundPageId')
In the Umbraco 7, if you´re using MVC Views or Partial View Macros razor the umbraco.library methods are replaced by @Umbraco. E.g the NiceUrl library method.
That doesn't appear to work either. I looked at the UmbracoHelper but it looks to be only for working with published content/media - it doesn't contain a method for GetCurrentNotFoundPageId().
BTW I'm coding inside a controller inherited from UmbracoController.
This may not be ideal but you can try something like this from your controller:
var error404Node = UmbracoSettings._umbracoSettings.SelectSingleNode("//error404"); if (error404Node != null) { var id = error404Node.InnerText; }
Note: It says UmbracoSettings is obsolete and to use UmbarcoConfiguration.Current.UmbracoSettings but I can't seem to find it and noticed other posts had similar issues trying to find it.
Also, you will have to modify the xpath if you have more than one <error404> node.
I ended up doing something very similar to what you suggested - only I opened the config file using the System.Xml.XmlDocument load method and then used the SelectNodes method.
I works and now I don't have to worry about something else in the future becoming obsolete and breaking my code.
Get Not Found Page Id from UmbracoSettings.config
Hello Umbraco Colleagues,
I'm using version 7.1.4 and I'm trying to write some code that will get the Not Found Page Id from UmbracoSettings.config: <error404>2172</error404>
In earlier versions, I would use umbraco.library.GetCurrentNotFoundPageId()
but that does not work any more. (umbraco.library' does not contain a definition for 'GetCurrentNotFoundPageId')
How can I get this node id programmatically?
Thanks,
David Hill
Hi David,
In the Umbraco 7, if you´re using MVC Views or Partial View Macros razor the umbraco.library methods are replaced by @Umbraco. E.g the NiceUrl library method.
You can find a list of some of the Umbraco helpers here: http://our.umbraco.org/documentation/Reference/Querying/UmbracoHelper/
I wonder if you can do something like this,
Hope this helps,
/Dennis
Hi Dennis,
That doesn't appear to work either. I looked at the UmbracoHelper but it looks to be only for working with published content/media - it doesn't contain a method for GetCurrentNotFoundPageId().
BTW I'm coding inside a controller inherited from UmbracoController.
Thanks. David
Hi David,
This may not be ideal but you can try something like this from your controller:
Note: It says UmbracoSettings is obsolete and to use UmbarcoConfiguration.Current.UmbracoSettings but I can't seem to find it and noticed other posts had similar issues trying to find it.
Also, you will have to modify the xpath if you have more than one <error404> node.
Mike
Hi Mike,
I ended up doing something very similar to what you suggested - only I opened the config file using the System.Xml.XmlDocument load method and then used the SelectNodes method.
I works and now I don't have to worry about something else in the future becoming obsolete and breaking my code.
Cheers,
David
is working on a reply...