Copied to clipboard

Flag this post as spam?

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


  • Kim Andersen 1447 posts 2197 karma points MVP
    Oct 19, 2010 @ 20:25
    Kim Andersen
    0

    Best way of getting value from web.config in XSLT

    Hi folks!

    I'm quite interested in the best way of getting a value from the web.config when working in XSLT.

    Let's say that I have the following value in my web.config.

    <configuration>
    <appSettings>
    ...
    ...
    <add key="myTest" value="1234" />
    </appSettings>
    ... ...
    </configuration>

    This could be a nodeId of some sort.

    I have made a small xslt-extension that looks like this:

    public static string configValue(string keyName){
        return ConfigurationManager.AppSettings[keyName];
    }

    And I can then use it in my XSLT like this:

    <xsl:value-of select="myPrefix:configValue('myTest')"/>

    The above code gives me the right value, 1234, from the web.config, so actually the extension works like I hoped. But is this the easiest/fastest/most wicked way of doing it? :)

    I need to say that I'm a frontend developer, and my C# skills are very, very limited, that's why I'd like to know if I'm doing it the right way :)

    /Kim A

  • Stefan Kip 1614 posts 4131 karma points c-trib
    Oct 19, 2010 @ 21:09
    Stefan Kip
    0

    I guess it is...

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Oct 19, 2010 @ 21:15
    Jan Skovgaard
    0

    I really don't think you can access a web.config file using XSLT...:-)

    And why would you do that? You just created at nice extension to achieve your goal. #H5YR

    /Jan

  • Kim Andersen 1447 posts 2197 karma points MVP
    Oct 21, 2010 @ 20:40
    Kim Andersen
    0

    Thanks for your inputs guys. I guess I'm doing "the right way" then :)

    Just wanted to know if there was any kind of "undocumented feature" for doing this. Thanks!

    /Kim A

  • Raghunath 1 post 21 karma points
    Oct 17, 2012 @ 17:04
    Raghunath
    0

    Hi Kim Andersen,

    Can you help me to implement the same functionality. I tried in similar way but I think something is missing in my implementation.

    <

     

    msxsl:scriptlanguage="vbscript"implements-prefix="iis"

    >

    function hasFunction1(key)

    hasFunction1=ConfigurationManager.AppSettings["TestConfig"]

    End Function

    </script>

    when I try to call this method from XSLT it is failing to load and I am not able to see why is it failing also. I think there is some problem with namespace, I mean ConfigurationManager namespace, how it will be known here? Is there something I am missing

     

  • Kim Andersen 1447 posts 2197 karma points MVP
    Oct 17, 2012 @ 21:21
    Kim Andersen
    0

    Hi there Raghunath

    Sorry to say, but I don't know how to code vbscript :(

    Can't you use some of the C# code provided above or do you have to use vbscript?

    /Kim A

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Oct 18, 2012 @ 00:04
    Chriztian Steinmeier
    6

    Hi all,

    Just saw this one pop up - just wanted to chip in with a clean XSLT solution :-)

    - lets say you need to know the Umbraco version:

    <xsl:variable name="config" select="document('../web.config')" /><!-- Yes, you can actually do that! -->
    <p>
      Umbraco Version: 
      <xsl:value-of select="$config//appSettings/add[@key = 'umbracoConfigurationStatus']/@value" />
    </p>
    /Chriztian
  • Kim Andersen 1447 posts 2197 karma points MVP
    Oct 18, 2012 @ 22:22
    Kim Andersen
    0

    Ahh, cool Chriztian. I didn't know that you could do it like that.

    Thanks for the tip :)

    /Kim A

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Nov 09, 2012 @ 19:28
    Jan Skovgaard
    0

    To all of you who come across this post, my assumption was very wrong and you should look at the answer provided by Chriztian. Please give him a hight five so others more easily can use some logical sense to figure out, which one is the correct solution.

    /Jan

  • 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.

Please Sign in or register to post replies