How to get current member in a Razor macro

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.


Just a slight change from @E.J.Brennan if the NULL is an issue you can check if you are logged on before trying to GetUser():

if (umbraco.library.IsLoggedOn())
{
  m = Membership.GetUser();
}

Starting from v7 you can use the MembershipHelper

@Members.CurrentUserName
@Members.GetCurrentMember()
@Members.GetCurrentMemberId()

Tags:

Macros

Umbraco