Copied to clipboard

Flag this post as spam?

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


  • Peter S 169 posts 587 karma points
    Jan 07, 2015 @ 11:54
    Peter S
    0

    Get value from umbracoSettings.config

    I've added a node to the errors section in umbracoSettings.config, error403 to be exact. How can I read this value? I can't find any documentation on this.

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Jan 07, 2015 @ 12:21
    Lee Kelleher
    104

    Hi Peter,

    Do you mean error404? or did you create your own custom error403 option?

    If you are after the error404 values, you can get them by using this API call:

    var errorPages = UmbracoConfig.For.UmbracoSettings().Content.Error404Collection;
    

    If you've created a custom error403 value, then there is no strongly-typed way to access those values, you'll either need to use a traditional way of opening an XmlDocument and querying it; or using one of the legacy API calls, like this:

    var nodes = umbraco.UmbracoSettings._umbracoSettings.SelectNodes("/settings/content/errors/error403");
    

    I must warn you that with using the legacy APIs, it will probably be removed in future versions of Umbraco.

    Good luck!

    Cheers,
    - Lee

  • Peter S 169 posts 587 karma points
    Jan 08, 2015 @ 07:52
    Peter S
    0

    I suppose you are right. I stored it in the AppSettings in web.config instead. Thanks for your reply!

  • karen 186 posts 461 karma points
    Jan 29, 2015 @ 00:44
    karen
    0

    What namespace do I need to include use this?  (I want to get the 404 value from the umbracosettings.config file) 

    var errorPages =UmbracoConfig.For.UmbracoSettings().Content.Error404Collection;

    Is there an easy way to look this sort of thing up ?

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Jan 29, 2015 @ 11:06
    Lee Kelleher
    1

    Hi Karen,

    The namespace is:

    using Umbraco.Core.Configuration;
    

    Cheers,
    - Lee

  • karen 186 posts 461 karma points
    Jan 29, 2015 @ 16:11
    karen
    0

    Ah, I realize now that this is in v7 (found this thread via search and didn't look at what group it was).

    I am in v6.2.1, so that is not working. Any ideas how to to it in v6 ?  I can repost this question in the extending umbraco forums.

     

  • karen 186 posts 461 karma points
    Jan 29, 2015 @ 23:57
    karen
    0

    Hi - I just realized you presented the answer already - thanks!

    var nodes = umbraco.UmbracoSettings._umbracoSettings.SelectNodes("/settings/content/errors/error403");

     

     

Please Sign in or register to post replies

Write your reply to:

Draft