This topic is locked

User Impersonation

2/17/2022 1:28:45 PM
ASPRunner.NET General questions
W
wshoap authorDevClub member

i need to create a button, that when clicked, will impersonate any user in my database? Has anyone done this yet? Thank you.

admin 2/17/2022

It is possible but we do not have an example. I'm pretty sure that simply logging in as a user is not complicated and you can use loginAs()
function of Security API. However, logging in back as an admin can be trickier as you do not want to do that manually.

W
wshoap authorDevClub member 2/17/2022

I want to put this code under a custom button, but it does not appear possible

dynamic userName = "User";
Security.loginAs(username, callEvent = true)

I am trying to understand where I can execute this code. Thank you.

admin 2/17/2022

In custom button it will work just fine, in the Server part. Just make sure you use a real username instead of "User".

Try this:
Security.loginAs("realusername");

or this:
Security.loginAs("realusername", false);

Reload the page after that to see the change applied.

W
wshoap authorDevClub member 2/18/2022

Thank you, I will try this. If I set the second parameter to true, does that reinitialize the app?

admin 2/18/2022

I don't even know what "reinitialize the app". Please refer to the documentation, it explains what exactly this parameter does.