Switching User based on Forms Authentication

If you need to code the following scenario:

switch between users in code, so no password is required. The business requirement is one of administrators being able to impersonate other users to essentially do their jobs for them.

Then using ASP.NET you would do :

FormsAuthentication.SetAuthCookie("user2", false); 
Response.Redirect("SomePage.aspx");



For instance, the user authenticates with credentials for 'user1' when requesting this page, a new auth cookie will be generated for 'user2' and the request for SomePage.aspx is made using this new auth cookie.



The authenticated user (User.Identity.Name) in SomePage.aspx will be 'user2'.



 



Hope this helps



Cheers

0 Responses to "Switching User based on Forms Authentication"

Post a Comment