Copied to clipboard

Flag this post as spam?

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


  • Kim Andersen 1447 posts 2196 karma points MVP
    Mar 18, 2010 @ 13:29
    Kim Andersen
    0

    Check if user is logged in from template

    Hi all.

    Is is possible to check if a user is logged in, from inside a template. I know that it's easy from XSLT, but in my case, I can't use XSLT to make this check. This can easily be piece of cake for some of you guys, but I'm not quite sure if this is possible.

    Regards,

    /Kim A

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Mar 18, 2010 @ 14:46
    Dirk De Grave
    2

    Kim,

    you can use any xslt extension method from your template as well. 

    <% if (umbraco.library:IsLoggedOn() { %>
    // do stuff if user is logged on
    <% } %>

     

    Cheers,

    /Dirk

     

  • Peter Dijksterhuis 1442 posts 1722 karma points
    Mar 18, 2010 @ 14:52
    Peter Dijksterhuis
    2

    You can perhaphs also use asp:LoginView?

  • Kim Andersen 1447 posts 2196 karma points MVP
    Mar 18, 2010 @ 16:59
    Kim Andersen
    0

    Thanks guys. Great that all the extensions are available in the templates as well. I knew it was easy for you guys :)

    And Peter, I think that I could have used this one as well actually. Have just seen the umbraco.tv episodes about members and protection, and it looks straight forward. So this could be a solution as well.

    /Kim A

  • Tyler Joyner 2 posts 22 karma points
    Dec 20, 2010 @ 20:44
    Tyler Joyner
    0

    Is it possible to insert the code on the template for all versions of umbraco?  We are running on 3 (not sure of the exact version number but I can grab it if i need to) and it seems that the code below is displayed directly on the page.

    <% if (umbraco.library:IsLoggedOn()) {%>
    // Call Umbraco Macros here
    <% } %>

    Any ideas?

  • wolulcmit 357 posts 693 karma points
    Sep 23, 2011 @ 08:36
    wolulcmit
    0

    Also trying to acheive the samefunctionality from a template, i.e check if a user is logged in or not
    If iuse the above code I get an error:

    Compiler Error Message: CS1026: ) expected

    Source Error:

     
    Line 15: </umbraco:Macro>
    Line 16: 
    Line 17: <% if (umbraco.library:IsLoggedOn()) {%> Line 18: // Call Umbraco Macros here
    Line 19: <% } %> 


    Am running umbraco 4.7.1
    is my code just borked?

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Sep 23, 2011 @ 09:45
    Dirk De Grave
    2

    Tim,

    If using the library function in templates (and therefore .net code), you need to replace the ':' with '.', so use

    Line15:</umbraco:Macro>
    Line 16:
    Line 17: <% if (umbraco.library.IsLoggedOn()) {%> Line 18: /
    /CallUmbracoMacros here
    Line19:<%}%>

    Furthermore, you'd better rely on the Membership api to achieve the same things, so you could aslo use

    HttpContext.Current.User.Identity.IsAuthenticated

    Cheers,

    Dirk

     

     

     

  • Simon Dingley 1474 posts 3431 karma points c-trib
    Sep 23, 2011 @ 09:46
    Simon Dingley
    2

    Tim/Dirk, I think you will need to replace the colon with a dot seperator as the colon has no place there in c#. So it should in fact read:

    if(umbraco.library.IsLoggedOn()){ %>
    // do stuff if user is logged on
    } %>
  • Brad Ford 34 posts 75 karma points
    Jul 17, 2013 @ 05:49
    Brad Ford
    0

    I had a problem with this but fixed it. So I deleted this post. 

Please Sign in or register to post replies

Write your reply to:

Draft