Click here to Skip to main content
15,888,065 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more: , +
Hi,

I know impersonation is possible with the below code
[DllImport("advapi32.dll", SetLastError = true)]
public static extern bool LogonUser(
string lpszUsername,
string lpszDomain,
string lpszPassword,
int dwLogonType,
int dwLogonProvider,
out IntPtr phToken);
But could you tell me whether I can impersonate without asking his password...
Thanks in advance!!!
Posted

1 solution

Do not use DllImport in a .Net application unless necessary. In this case, impersonation is native to .Net so use .Net libraries.

However, if you want the code to run as a user without asking for their password then you have to turn on Windows Authentication in IIS so that windows will authenticate them and then also turn impersonation on in web.config. See https://msdn.microsoft.com/en-us/library/aa292118(v=vs.71).aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900