Impersonation in Web Applications

G

Guest

Hi,

I have a typical scenario, I have web page which tries to list the files on
the remote share. When i try to access the remote network path like
"\\machinename\folder" using web application cs file it gives access denied
error. Also i have have set the web.config identity impersoante=true, my IIS
has only Intergrated windows authentication enabled as this is a intranet web
application. My repository is on different machine and not on the server
which the web based intranet application is hosted. Any links or docs would
be of great help!!

Regards,
Prasad
 
V

Vadym Stetsyak

IntPtr accountToken = WindowsIdentity.GetCurrent().Token;

// Impersonate a Windows identity.
// Retrieve the Windows identity using the specified token.
WindowsIdentity windowsIdentity = new WindowsIdentity(logonToken);

// Create a WindowsImpersonationContext object by impersonating the
// Windows identity.
WindowsImpersonationContext impersonationContext =
windowsIdentity.Impersonate();

//do your stuff here

impersonationContext.Undo();

}
 
J

Joshua Flanagan

Vadym said:
IntPtr accountToken = WindowsIdentity.GetCurrent().Token;

// Impersonate a Windows identity.
// Retrieve the Windows identity using the specified token.
WindowsIdentity windowsIdentity = new WindowsIdentity(logonToken);

// Create a WindowsImpersonationContext object by impersonating the
// Windows identity.
WindowsImpersonationContext impersonationContext =
windowsIdentity.Impersonate();

//do your stuff here

impersonationContext.Undo();

}


Just a heads up - I do not think this will work with the default
security settings on Windows 2000 - I think it requires that you give
the ASPNET account the "act as part of the operating system" right.
It should work fine on Windows XP and 2003.
 

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

Top