Copied to clipboard

Flag this post as spam?

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


  • Bart de Jonge 29 posts 51 karma points
    Aug 12, 2009 @ 16:14
    Bart de Jonge
    0

    umbraco.library:IsLoggedOn() returns NullReferenceException

    Hi,

    When I try to use umbraco.library:IsLoggedOn() function I always get a NullReferenceException.
    I saw some examples on the forum like: <xsl:when test="umbraco.library:IsLoggedOn() = 1"> but that doesn't work for me!

    do I have to change setting before ik can use the IsLoggedOn function or am I missing something here?

    thanks Bart


  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Aug 12, 2009 @ 16:21
    Douglas Robar
    102

    That should work. Though remember that IsLoggedOn() is very simple and doesn't do any checking to see if the page is protected and if the logged-on user has access. Here are common xslt's I use.

    If you can't get this to work, tell us more about your installation (version, etc.), your xslt code, and the error (does it happen during xslt save, when run on the page, etc.)

     

    Change login link text if user is already logged in

        <xsl:choose>
        <xsl:when test="umbraco.library:IsLoggedOn() = true()">
            <a href="/login.aspx">
                Log Out <xsl:value-of select="umbraco.library:GetCurrentMember()/@loginName"/>
            </a>
        </xsl:when>
        <xsl:otherwise>
            <a href="/login.aspx">Login</a>
        </xsl:otherwise>
        </xsl:choose>




    Show list of items unique to the logged-in member

    <ul class="ListOfMedia">
        <xsl:for-each select="$source/node [
                string(data [@alias='umbracoNaviHide']) != '1'
                and (umbraco.library:IsProtected(@id, @path) = false()
                    or umbraco.library:HasAccess(@id, @path) = true())
                ]">
            <li>
                <a href="{umbraco.library:NiceUrl(@id)}">
                    <xsl:value-of select="@nodeName"/>
                </a>
            </li>
        </xsl:for-each>
        </ul>

    cheers,
    doug.

     

  • Bart de Jonge 29 posts 51 karma points
    Aug 13, 2009 @ 10:15
    Bart de Jonge
    0

    Hi doug,

    you're right I should give some more info.

    We use umbraco umbraco v 4.0.2.1 (Assembly version: 1.0.3441.17657)

    error is:

    Error occured

    System.NullReferenceException: Object reference not set to an instance of an object. at umbraco.BusinessLogic.StateHelper.GetCookieValue(HttpContext context, String key) at umbraco.BusinessLogic.StateHelper.HasCookieValue(String key) at umbraco.cms.businesslogic.member.Member.CurrentMemberId() at umbraco.cms.businesslogic.member.Member.IsLoggedOn() at umbraco.library.IsLoggedOn()

    and it appears when I save the xslt file.

    xslt file
    <xsl:choose>
    <xsl:when test="umbraco.library:IsLoggedOn() = true()">
    logged on
    </xsl:when>
    <xsl:otherwise>
    not logged on
    </xsl:otherwise>
    </xsl:choose>

    also when I use other functions from the library (like HasAccess or IsProtected) I get no errors!
    any idea Doug?

     

    Cheers Bart


  • Petr Snobelt 923 posts 1535 karma points
    Aug 13, 2009 @ 11:36
    Petr Snobelt
    0

    I have same problem sometimes, ignoring it using skip error checking works. I suppose httpContext or something similar isn't sometimes available.  

  • Bart de Jonge 29 posts 51 karma points
    Aug 13, 2009 @ 11:52
    Bart de Jonge
    0

    Hi Petr,

    thanks for your reply, indeed skipping the error check seems to work!

    Do you know if there is some proper documentation on using the umbraco.library?
    I did some googling but it seems it is not documented!

    cheers Bart

  • Bart de Jonge 29 posts 51 karma points
    Aug 13, 2009 @ 14:31
    Bart de Jonge
    0

    I found the problem!

    you have to make sure you defined some members, membergroups and membertypes before you can use the IsLoggedOn function :-)
    The umbraco member controls which is in the package repository can be very handy!!

    cheers Bart


  • curlybub 133 posts 107 karma points
    Mar 08, 2010 @ 03:58
    curlybub
    0

    Hi Bart,

    Can you explain further what you meant with "you have to make sure you defined some members, membergroups and membertypes before you can use the IsLoggedOn function :-)"

    Im encourtering the same problem here.

    Thank you.


    Regards,
    Harry

Please Sign in or register to post replies

Write your reply to:

Draft