1

I would like to change the logged in user to another user temporarily to do some process.

For example, say I am logged in as "Joe". In my method, I want to make the logged in user from "Joe" to "SuperUser", do some process, then change the logged in user back to "Joe". Can someone help with this?

TruMan1
  • 33,665
  • 59
  • 184
  • 335

3 Answers3

1

I think you want ASP.NET impersonation for that. Check out what it is and how to use it. Something like this (from the second link):

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();

EDIT: For ASP.NET Membership, see this SO question and this answer.

Community
  • 1
  • 1
ChessWhiz
  • 4,656
  • 3
  • 26
  • 40
0

Although I fail to understand why a user becomes a superuser in a real world application, I think you could look at asp.net impersonation technique...

hth.

Sunny
  • 6,286
  • 2
  • 25
  • 27
  • But ASP.NET impersonation is on the Windows OS level. I want to impersonate with the ASP.NET Membership level. I am extending a web app to provide access level to an object for all who is in the creator's role. The built-in methods check rights based on the logged in user and not the logged in role, I have to impersonate the membership user. Even if I can check the rights of the role, it wouldn't work in my case because the creator has full access to all items they own (even if they don't have general modify rights). So I want to give rights to the creator's role instead of the creator's user – TruMan1 Apr 02 '10 at 17:06
0

From the answer to this question: Elevating process privilege programmatically?

You can indicate the new process should be started with elevated permissions by setting the Verb property of your startInfo object to 'runas', as follows:

startInfo.Verb = "runas";

This is changing your Windows user. If you want to change the ASP.NET user who logged in to your page, then this is not what you are looking for.

Community
  • 1
  • 1
Neil
  • 7,227
  • 5
  • 42
  • 43