Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi,

I have requirement to log in as another user. The description is like, we have admin login and when I give a person id, I should be able to open the application in new tab as that user. It should be similar like the actual person has logged in.

Can you please suggest some approach.
Posted
Comments
ZurdoDev 20-Mar-15 8:32am    
You just have to write the code. There's no magic button. Wherever your login logic is add a case for when you are coming in as admin and trying to do run as.
F-ES Sitecore 20-Mar-15 9:48am    
The approach would be...check if the current user is an admin user, if they are make the other user the current user. That will let the admin user browse the site as that user.

As you haven't explained how you are managing users and roles it's hard to give anything that is specific to your application.
Arkadeep De 20-Mar-15 13:55pm    
If you managing admin and other users differently then just check whether the user id is inputting is present or not. and obviously keep a track that the request is coming from admin. If the user is present then just logged in with that id. create a session with that id.
Gopi Kishan Mariyala 23-Mar-15 2:47am    
Thanks for your suggestions

1 solution

What you are after is referred to as user impersonation for IIS...

C#
System.Security.Principal.WindowsImpersonationContext impersonationContext;
impersonationContext = 
    ((System.Security.Principal.WindowsIdentity)User.Identity).Impersonate();

//Insert your code that runs under the security context of the authenticating user here.

impersonationContext.Undo();


You will find a really useful article here...

https://support.microsoft.com/en-us/kb/306158[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900