0

In a certain situation, I want a request to execute as a user different than the one actually logged in. So, when User A requests a particular page, from code I want to switch it execute under the user account of User B -- only for this single request (or even for a single block of code...)

I've used this:

FormsAuthentication.SetAuthCookie("UserB")

This works, but it's persistent. When I request a new page, I'm now logged in as User B, which is not what I want.

Is this possible? I've RTFM'd up and down for this.

Edit: I may have found an answer, which I posted below. Looking for confirmation or refutation of this solution.

Deane
  • 8,269
  • 12
  • 58
  • 108

1 Answers1

0

I think I might have found it. I'm not 100% sure, but this works. I just don't know if it's completely correct or if there's something I'm not considering.

HttpContext.Current.User = PrincipalInfo.CreatePrincipal("UserB");

Again, this seems to do what I originally wanted. If you have experience that would prove me right or wrong, please comment.

Deane
  • 8,269
  • 12
  • 58
  • 108