Get the Current User Name

Sherry Collins asked on June 3, 2015 17:57

I need to get the current user logged into my website. I thought I was getting it with Eval("NodeOwner"), but that is returning the person who wrote the blog. What would give me who is logged in.

Thanks.

Correct Answer

Brad Vrudney answered on June 3, 2015 22:45

the hash is the signed macro. Kentico does that for security purposes so it knows who created it, and what permissions it has. I think your issue may be that you are using {%%} which is for text transformations, rather than ascx. try changing it to: <%CurrentUser.UserName%>

0 votesVote for this answer Unmark Correct answer

Recent Answers


Brad Vrudney answered on June 3, 2015 18:24 (last edited on June 3, 2015 18:28)

{%CurrentUser.UserName%} or {%CurrentUser.UserID%}

You can also expand it to other properties:

<%# GetUserFullName(Eval<int>("UserID")) %>

https://docs.kentico.com/display/K8/Reference+-+Transformation+methods

1 votesVote for this answer Mark as a Correct answer

Sherry Collins answered on June 3, 2015 21:16 (last edited on June 3, 2015 21:17)

I get very strange results back in my Json string when I use this {%CurrentUser.UserName%} This is what is in the Json String UserName={%CurrentUser.UserName|(user)RT-ccollins|(hash)2a47674f8d55abfad7453d363e2de73a82497eb89a59e13985d1cfa210980863%}

This evaluates to NULL and I am getting a SQL Error.

This is my transformation

<br><span id="newlikes" data-currentuser={%CurrentUser.UserName#%} data-blogposttitle="<%# Eval("DocumentID")%>"><a href="#"><%#GetBlogLikesCount(Eval<int>("DocumentID"))%> Likes</a></span></div>

Am I doing something wrong?

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.