When I try to use umbraco.library:IsLoggedOn() function I always get a NullReferenceException. I saw some examples on the forum like: <xsl:whentest="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?
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
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?
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!!
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 :-)"
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
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: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
<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.
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:
and it appears when I save the xslt file.
also when I use other functions from the library (like HasAccess or IsProtected) I get no errors!
any idea Doug?
Cheers Bart
I have same problem sometimes, ignoring it using skip error checking works. I suppose httpContext or something similar isn't sometimes available.
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
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
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
is working on a reply...