Impersonating live site user in kentico 12 mvc

Yowaraj Chhetri asked on July 31, 2019 02:16

Hi,

My client has a requirement of doing some task by their staff on the live site portal on behalf of customers. In that case, rather than login with customers login credential. I was looking a way to impersonate live site authenticated user by the staff members. Staff members will use CMS interface and customer will use mvc live site. Let me know if this is even possible in kentico 12 mvc or if there is a plan to support such features.

Thank you

Recent Answers


Dragoljub Ilic answered on July 31, 2019 10:19 (last edited on July 31, 2019 10:20)

Hi,

I'm not sure that there is an out of the box support for impersonate users in MVC, but if you followed documentation for implementing login features, you can do a simple workaround. Instead of using: SignInManager.PasswordSignIn(username, password, false, false); you can sign in users without knowing password with this peace of code:

User user = UserManager.FindByName(model.UserName);
SignInManager.SignIn(user, true, true);

This will allow you to log in as 'impersonated' user into portal on MVC side. This feature should be enabled only for users with admin privilege level, so keep it in mind to restrict it on the site.

Best regards, Dragoljub

1 votesVote for this answer Mark as a Correct answer

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