If you ever have done work with C# and AD you probably would have come across various issues. One of the first issues usually relates to authentication. In an earlier posting, I already proved that win32 logon is better than Ldap binds and so I am going to assume that this is the approach you are all taking. Now, let's say you want the hex code error and also try different types of logon such as LOGON32_LOGON_INTERACTIVE or LOGON32_LOGON_NETWORK. This little utility will allow you to switch between the different options and easily test and get the hex code error.
Here is a snippet of the code which you can find
here:
private void btnLogonUser_Click(object sender, EventArgs e)
{
IntPtr token = IntPtr.Zero;
int logonType = (int)((ComboItem)cbLogonType.Items[cbLogonType.SelectedIndex]).Value;
bool isOk = LogonUser(tbUsername.Text, tbDomain.Text, tbPassword.Text, logonType, LOGON32_PROVIDER_DEFAULT, ref token);
int err = GetLastError();
if(isOk) {
tbStatus.Text = "Status";
}
else {
tbStatus.Text = String.Format("Error: 0x{0:X} ({0})", err, err);
}
}
No comments:
Post a Comment