Umbraco.Library.IsLoggedOn() does not work from XS

2019-08-01 21:41发布

This is simple xslt, that shows the login status of the current user. Everything worked fine on development server, but once we've setup app on production, umbraco.librarty.IsLoggedOn() started always to return false.

Application uses method umbraco.libraty.IsLoggedOn() from .NET code and from there it returns proper value, but from xslt doesn't.

 <xsl:choose>
  <xsl:when test="umbraco.library:IsLoggedOn() = true()">
   You are logged in as 
    <q>
      <xsl:variable name="user" select="umbraco.library:GetCurrentMember()/@loginName"/>
      <xsl:value-of select="$user"/>
    </q>.  This is <a href="/profile">your profile</a>.
  </xsl:when>
  <xsl:otherwise>
   You are not logged in.
    <a href="/registruj-se">Log in</a>.
  </xsl:otherwise>
</xsl:choose>

For non-umbraco developers: the library.IsLoggedOn() function checks HttpContext.Current.User and HttpContext.Current.User.Identity.IsAuthenticated to see if you is logged in or not.

Maybe it is a problem with cookies and XSLT? Anyone have a clue? Tnx

标签: xslt umbraco
2条回答
时光不老,我们不散
2楼-- · 2019-08-01 22:27

Change

<xsl:when test="umbraco.library:IsLoggedOn() = true()"> 

to

<xsl:when test="umbraco.library:IsLoggedOn()"> 
查看更多
在下西门庆
3楼-- · 2019-08-01 22:45

Ok, this is solution to my problem.

The session was not available from xslt, neither from ascx control that tried to access session from codebehind. Our application is 99% using asp.net webservice with methods marked with [WebMethod(EnableSession = true)]. Inside of these methods, session was available. That made me think that session is actually disabled on the web site by default.

After some googling, I find out that I have to add this property to web.config file:

<system.webServer>
<modules runAllManagedModulesForAllRequests="true">

Apparently, the machine.config in our development had this property as default, and production server didn't, so it needed to be changed in web.config.

查看更多
登录 后发表回答