Impersonate via code?

G

Guest

I know that you can do different things to enable different types of
impersonation using the config files (like set it up so the end user is the
one being impersonated, or set it up so the asp.net WP runs as a specific
domain user).

But, what I am wondering if it is possible to change the impersonation
account via code? For example, lets say that for 1 function you need to
access a remote file share to grab a file. Is there a way to, while that 1
function is running, use the privledges of a different user and then return
to the original privledges after the function has retreived the file?
 
R

Rick Strahl [MVP]

Hi,

Given the right permissions you can probably use the LogonUser API to logon
a specific user, but you would need username and password to logon.

Haven't tried this but it should work given that your Web Application has
permissions to call API routines.

Going back to the account that was running is more difficult. You can use
RevertToSelf() which will revert back to the underlyig machine account (ie.
NETWORK SERVICE most likely) or whatever account IIS (in IIS 5) or the
Application Pool (in IIS6) is running under.

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
http://www.west-wind.com/wwThreads/
 
R

Rick Strahl [MVP]

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,525
Members
44,997
Latest member
mileyka

Latest Threads

Top