Running a function as a specific user account.

I suspect the answer to this problem is no, however here it is.

Is there any way to run a specific function of code under a specified user account? I have an asp application (intranet) that uses the Integrated security method. ie if MyDomain\UserA is the owner of the browser, then MyDomain\UserA is the account that runs the code.

I have a page that need to use the current user for most of the code, however one function on that page needs to use a specific user account to get the job done.  I need to know how to run the page under integrated security, and yet run the one function as Mydomain\Superuser.

A web config file in folder wont do it, as it changes the security method for the entire page. So I am looking for a line(s) of code that can be contained within my function to swap the user

I need something like:-

CurrentUser.Name="MyDomain\Superuser"
Currentuser.Password="abc12345"

{execute code that needs new security access}

CurrentUser.Name= {Integrated user etc}

{rest of code that needs current user permissions now runs}
Can this be done?
LVL 5
CaptainRantflapsAsked:
Who is Participating?
 
ihenryCommented:
Yes, impersonation is the answer. However, depends on operating system on where your code is running; you'd need to set some security settings. This is best sample code I've seen so far:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemsecurityprincipalwindowsimpersonationcontextclasstopic.asp
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.