Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • David F. Hill 122 posts 242 karma points
    Jun 30, 2014 @ 22:00
    David F. Hill
    0

    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

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jun 30, 2014 @ 22:16
    Dennis Aaen
    0

    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.

    <a href="@Umbraco.NiceUrl(1234)">My link</a>

    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,

    @Umbraco.GetCurrentNotFoundPageId()

    Hope this helps,

    /Dennis

  • David F. Hill 122 posts 242 karma points
    Jun 30, 2014 @ 22:33
    David F. Hill
    0

    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

  • Mike Hennessy 1 post 21 karma points
    Jun 30, 2014 @ 23:17
    Mike Hennessy
    0

    Hi David,

    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.

    Mike

  • David F. Hill 122 posts 242 karma points
    Jun 30, 2014 @ 23:31
    David F. Hill
    0

    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

Please Sign in or register to post replies

Write your reply to:

Draft