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

荒凉一梦 提交于 2019-12-11 12:24:34

问题


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


回答1:


Change

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

to

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



回答2:


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.



来源:https://stackoverflow.com/questions/3361706/umbraco-library-isloggedon-does-not-work-from-xslt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!