Impersonation code
From: Pramod (pramodi_at_cybage.com)
Date: 05/12/05
- Next message: Nicole Calinoiu: "Re: Distributed winforms application security"
- Previous message: Richard Ruben: "Re: IsInRole groupname with white space."
- Next in thread: Joe Kaplan \(MVP - ADSI\): "Re: Impersonation code"
- Reply: Joe Kaplan \(MVP - ADSI\): "Re: Impersonation code"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Thu, 12 May 2005 14:03:38 +0530
Hi,
I have the following Impersonation code. This code is in C# and I want
to retrieve the data from the SQL server database using the Specified
windows username and password.
public bool ImpersonateUser(string sUsername, string sDomain, string
sPassword)
{
bool bImpersonated = false;
pExistingTokenHandle = new IntPtr(0);
pExistingTokenHandle = IntPtr.Zero;
try
{
const int LOGON32_PROVIDER_DEFAULT = 0;
// create token
//const int LOGON32_LOGON_INTERACTIVE = 2;
const int LOGON32_LOGON_NETWORK = 3;
//const int SecurityImpersonation = 2;
// get handle to token
bImpersonated = LogonUser(sUsername, sDomain, sPassword,
LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT,
ref pExistingTokenHandle);
}
catch (Exception e)
{
ATrace.WriteLine( ATrace.CATEGORY.ERROR,
"SQLQueryBuilder::ImpersonateUser - " + e.Message );
}
return bImpersonated;
}
This code does not throw any exception but returns false.
Interesting thing is, I have created a sample application similar to
this in ASP.Net. The same application works but not mine which is ther
in project.
So, is ther any prequisite to run that code ???
Or is ther any project settings ???
If you know, then plz let me know ASAP
Thanks,
Pramod.
- Next message: Nicole Calinoiu: "Re: Distributed winforms application security"
- Previous message: Richard Ruben: "Re: IsInRole groupname with white space."
- Next in thread: Joe Kaplan \(MVP - ADSI\): "Re: Impersonation code"
- Reply: Joe Kaplan \(MVP - ADSI\): "Re: Impersonation code"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|