Copied to clipboard

Flag this post as spam?

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


  • Darryl Godden 145 posts 197 karma points
    May 20, 2010 @ 17:51
    Darryl Godden
    0

    Index outside of bounds of the array

    Hi all,

    I am trying to use a function that I have added to the XSLTHelper class. The function returns a location value dependant on the IP address. What I can't get to work is if I use the RequestServerVariables it returns the IP address without error. If I statically type the IP address into the XSLTHelper:GetLocation it returns the locality, however, if I put the variable name into the GetLocation I get 'IndexOutOfRangeException', here is the code:

    <xsl:variable name="ipAddress" select="umbraco.library:RequestServerVariables('REMOTE_ADDR')"/>
    <xsl:variable name="locality" select="RaymondGubbayLib.XSLTHelper:GetLocation($ipAddress)"/
  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    May 20, 2010 @ 18:02
    Morten Bock
    0

    Do you get the error when saving, or at runtime?

  • Darryl Godden 145 posts 197 karma points
    May 21, 2010 @ 09:28
    Darryl Godden
    0

    When saving.

  • Tommy Poulsen 514 posts 708 karma points
    May 21, 2010 @ 09:59
    Tommy Poulsen
    0

    Now I don't know this particular extension, but have you tried adding a test for non-empty ip address before the GetLocation, i.e. something like this (out of my head):

     

    <xsl:variable name="locality" 
    <xsl:choose">
    <xsl:when
    test="$ipAddress != ''>
     <xsl:value-of select="RaymondGubbayLib.XSLTHelper:GetLocation($ipAddress)"/>
    </xsl:when>
    <xsl:otherwise>
    whatever is necessary here
    </xsl:otherwise>
     </xsl:choose>
  • Darryl Godden 145 posts 197 karma points
    May 21, 2010 @ 10:20
    Darryl Godden
    0

    Nope, still doing it:

    <xsl:variable name="ipAddress" select="umbraco.library:RequestServerVariables('REMOTE_ADDR')"/>
    
    <xsl:choose>
    <xsl:when test="$ipAddress != ''">
        <xsl:variable name="locality" select="RaymondGubbayLib.XSLTHelper:GetLocation($ipAddress)"/>
        <div>
            <xsl:value-of select="$locality"/>
        </div>
    </xsl:when>
    </xsl:choose>
  • Tommy Poulsen 514 posts 708 karma points
    May 21, 2010 @ 10:33
    Tommy Poulsen
    0

    Hmm, if you are sure it's the GetLocation call that fails it's probably because it cannot validate that $ipAddress is an non-empty string. You could try adding a string cast

    RaymondGubbayLib.XSLTHelper:GetLocation(string($ipAddress))
  • Darryl Godden 145 posts 197 karma points
    May 21, 2010 @ 10:38
    Darryl Godden
    0

    I think it's to do with the web being on my local machine, if I test to see that 'LOCAL_ADDR' is not 127.0.0.1 it works fine, strange.

  • Darryl Godden 145 posts 197 karma points
    May 21, 2010 @ 10:42
    Darryl Godden
    0

    Yep, works with this:

    <xsl:if test="$ipAddress != '127.0.0.1'">
        <div>
            <xsl:variable name="locality" select="RaymondGubbayLib.XSLTHelper:GetLocation($ipAddress)"/>
        </div>
    </xsl:if>

     

    Thanks for your help guys.

  • Tommy Poulsen 514 posts 708 karma points
    May 21, 2010 @ 10:43
    Tommy Poulsen
    0

    Have you tried with testing for others ip's also - it sounds a bit weird

  • Darryl Godden 145 posts 197 karma points
    May 21, 2010 @ 11:37
    Darryl Godden
    0

    Yeah, we have IPs' for Scotland, London, Sheffield and Coventry as it is an arbitrary GeoLocation service we're looking to provide. It seems like when the IP address is not localhost (127.0.0.1) it works fine.

  • Darryl Godden 145 posts 197 karma points
    May 21, 2010 @ 11:38
    Darryl Godden
    0

    This is the final (working) XSL:

    <xsl:variable name="ipAddress" select="umbraco.library:RequestServerVariables('LOCAL_ADDR')"/>
    
    <xsl:variable name="area">
    <xsl:choose>
    <xsl:when test="$ipAddress != '127.0.0.1'">
        <xsl:value-of select="RaymondGubbayLib.XSLTHelper:GetLocation($ipAddress)"/>
    </xsl:when>
    <xsl:otherwise>
    <xsl:text>South</xsl:text>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>
Please Sign in or register to post replies

Write your reply to:

Draft