How to get the current Razor macro member

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

The problem is that inside the Razor macro, I cannot get the current Member that is accessing the site. I tried the following methods:

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

Is there any other way to get the current Member view, as the above methods do not work in my case?

+6
source share
3 answers
 var m = Membership.GetUser(); 

This should work just checking it out 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 what you want.

+11
source

Just a small change from @EJBrennan if the NULL problem is a problem that you can check if you are logged in before trying GetUser ():

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

Starting from v7 you can use MembershipHelper

 @Members.CurrentUserName @Members.GetCurrentMember() @Members.GetCurrentMemberId() 
+3
source

Source: https://habr.com/ru/post/926853/


All Articles