views:

62

answers:

3

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?

A: 

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
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
+1  A: 

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.

ChessWhiz
Is this for the ASP.NET user (Membership provider)? The membership provider is what I need to work with.
TruMan1
I've edited my answer with info on ASP.NET Membership impersonation.
ChessWhiz
A: 

From the answer to this question: http://stackoverflow.com/questions/133379/elevating-process-privilege-programatically

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.

Neil Whitaker