Kentico User GUID

Shane Cao asked on July 9, 2019 17:34

Is there anyway to retrieve the users GUID after a user has logged into the CMS site?

Currently on login I have the page redirecting to a users profile page that I made using a custom database using react as my front end. It loads the page fine but I was hoping to take the GUID and something else unique and concatenate that to my url. I would then use javascript to split the url and grab the query parameters and make and ajax request that would run before page loads to build the page.

So basically I need a way to add query parameters to the url after a user has logged in.

Any help would be greatly appreciated, or maybe a different approach.

THANKS!

Recent Answers


Brenden Kehren answered on July 9, 2019 17:41

I'd suggest using their username as the URL parameter but the GUID will work. Once you have the user object, you can get the GUID by accessing the objects property.

UserInfo user = MembershipContext.AuthenticatedUser;  
string guid = user.UserGuid.ToString();
0 votesVote for this answer Mark as a Correct answer

Roman Hutnyk answered on July 11, 2019 08:51 (last edited on December 10, 2019 02:31)

I'd recommend to pass user identifier (id, guid or anything else) in more secure way:

You're probably adding React container (root) to the page either through template layout or web part like static html. Last one is where you could use Kentico macro:

<div id="root" user="{%CurrentUser.ID|(identity)GlobalAdministrator%}"></div>

So now you could easily get the value in React root component and pass it through components tree:

const el = document.getElementById('root');
var user = el.getAttribute('user');
ReactDOM.render(<App userId={user} />, el)

This approach gives you cleaner URL and reduces chances someone will play with the value in the URL.

0 votesVote for this answer Mark as a Correct answer

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