Search code examples
macrosumbraco

How to get current member in a Razor macro


I have asked this question on the Our Umbraco forums, however I wanted to also increase my chances of getting a solution by posting the same question here.

The issue I have is that, inside a Razor macro, I'm unable to get the current Member who is accessing the site. I have tried the following methods:

  • Calling Member.GetCurrentMember(), but this returns NULL.
  • Calling Membership.GetUser(), but this returns NULL
  • Calling UmbracoEnsuredPage.CurrentUser returned NULL;

Is there another way to get the current Member seeing how the above methods do not work in my case?


Solution

  • var m = Membership.GetUser(); 
    

    That should work, just verified it myself on 4.7.1; it will return NULL if you are not logged in as a member, but when you log in it should get you what you want.