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 48 posts 68 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 2120 posts 3988 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 731 posts 1708 karma points
    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 48 posts 68 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 4376 posts 9994 karma points admin mvp 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 48 posts 68 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:

Draft is the community mothership for Umbraco, the open source cms. With a friendly forum for all your questions, a comprehensive documentation and a ton of packages from the community. This site is running Umbraco version 7.3.1