In this MSDN article on "How to implement impersonation in an ASP.NET application" they list 4 different ways to change the account that's used to execute the web request. Unfortunately, it doesn't describe the differences between these alternatives.
I'm trying to impersonate the IIS authenticated user to copy some files off their local machine. It works when I use the WIN32 api LogonUserA
and impersonate a specific user. But I need the webapp to work with many users (I don't have an account that can access everyone's files).
I thought simply setting Impersonate = "true" and configuring IIS should work but something is different. When I check Environment.UserName it appears to be impersonating the correct account but I am getting "Access is denied" errors.
Anyone know the difference between these impersonation methods? Is it possible to impersonate the IIS authenticated user and then do some file operations with it?
Update: From the feedback I've been getting I need to be more clear about what I'm facing.
Environment setup: IIS: disable anonymous authentication, enable integrated windows authentication ASP.Net's web.config: authentication mode = "windows", impersonate = true, deny anonymous users
Suppose I'm accessing the page as "userA":
Scenario 1: impersonate the IIS Authenticated user
try{
File.Copy(srcFile, destFile); // Access Denied even though userA has access to srcFile.
} catch(Exception ex) {
...
}
Scenario 2: impersonate userA with LogonUser
try{
// Impersonater is a wrapper around the WIN32 LogonUser API
using(Impersonater imp = new Impersonator("domain", "userA", "pwd"))
{
File.Copy(srcFile, destFile); // Works
}
} catch(Exception ex) {
...
}
In both cases, I'm impersonating "userA".