Last chance to get discounted tickets to Codegarden... Price goes up on Tuesday at 20:00 CEST!

Copied to clipboard

Flag this post as spam?

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

  • Jason Evans 50 posts 70 karma points
    Oct 03, 2012 @ 17:06
    Jason Evans

    How to get current member in a Razor macro.

    Hi there.

    I'm unable to get the current member inside a Razor macro.

    I have tried the following methods:

    • Calling Member.GetCurrentMember(), but this returns NULL.
    • Calling Membership.GetUser(), but this returns NULL

    Basically I need to get the current member in orde to do some processing using that member's ID.

    Are the above the only ways of trying to get the current member, or is there an alternative?


  • Fuji Kusaka 2196 posts 4189 karma points
    Oct 03, 2012 @ 19:55
    Fuji Kusaka

    Hi Jason,

    When using razor remember to add those and run a check to see if a member is well login.

    @using umbraco.cms.businesslogic.member
    @using System.Web 
    @using System.Web.Security

         var currentUser = Member.GetCurrentMember();
          if (currentUser!=null)
                  var userName = currentUser.Text;
  • Dan Diplo 1234 posts 4444 karma points MVP
    Oct 04, 2012 @ 10:18
    Dan Diplo

    You can also access member properties via standard ASP.NET provider model, so you can do this:

    if (User.Identity.IsAuthenticated)
        <p>Name is @User.Identity.Name</p>
  • Jason Evans 50 posts 70 karma points
    Oct 04, 2012 @ 10:20
    Jason Evans

    Hi Fuji.

    Thank you for your reply. I managed to get assistance with this issue from someone, who pointed out that I needed to right-click on the root "Content" node in the Umbraco content tree, and then choose "Republish".

    After I did that, all of the images which were originally missing now appeared. So after manually running SQL scripts for the images, I need to manually "Republish" the content.

    EDIT: Please ignore the above comment, it was meant for another question I had asked! Doh.

  • Jeroen Breuer 4857 posts 12098 karma points MVP 3x admin c-trib
    Oct 04, 2012 @ 18:18
    Jeroen Breuer

    If you use the Member API it does a lot of calls to the database. This example can help:


  • Jason Evans 50 posts 70 karma points
    Oct 05, 2012 @ 10:03
    Jason Evans

    Hi guys.

    Right I've been away for a couple of days, so sorry for the delay.

    This turned out to be a total DOH! moment. Turns out that the Umbraco client site that I'm working one does not display a login page by default (don't ask), so each time I was testing my code, I wasn't actualyl logged in - I did not know that, since it never asked me to log in!!! Argh.

    I have to manually navigate to the login page, enter a username and passwed and hey presto all the Member API stuff now works. Humph.

    Thanks for all your efforts though guys.


Please Sign in or register to post replies

Write your reply to: