Impersonate user in Episerver
TLDR:
You can use this file:
Put it on your website root folder, then fill in the user name to impersonate (or search for it first if you are not sure about the user name)
Background:
Sometime that you might need to log in multiple users to test the personalization behavior but forgot the password or lazy to enter it :))
It would be great to just impersonate by fill in the user name. And fortunately, we can easily done it by using Episerver UI provider.
First we need to find the user by name to see if it exist:
userProvider.FindUsersByName(userName, 0, 1, out totalRecord).FirstOrDefault();
But we can't actually sign in without the password, so a hack used to reset password to "P@ssw0rd"
uiUserManager.ResetPassword(user, password);
Finally, time to sign in
uiSignInManager.SignIn(user.ProviderName, user.Username, password);
Detail code could be found here: https://github.com/KhanhPham2411/Episerver-util-aspx/blob/main/impersonate.aspx
Comments
Post a Comment