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 71 karma points
    Oct 03, 2012 @ 17:06
    Jason Evans
    1

    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?

    Cheers.
    Jas.

  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 03, 2012 @ 19:55
    Fuji Kusaka
    0

    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;
                            
                 @userName
           }
     
      }
  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Oct 04, 2012 @ 10:18
    Dan Diplo
    0

    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 71 karma points
    Oct 04, 2012 @ 10:20
    Jason Evans
    0

    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 4908 posts 12265 karma points MVP 5x admin c-trib
    Oct 04, 2012 @ 18:18
    Jeroen Breuer
    0

    If you use the Member API it does a lot of calls to the database. This example can help: http://our.umbraco.org/forum/developers/extending-umbraco/27626-Accessing-Member-Information?p=1#comment105493.

    Jeroen

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

    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.

    Cheers.
    Jas. 

Please Sign in or register to post replies

Write your reply to:

Draft