using System.Web.Security;
using System.Runtime.InteropServices;

[DllImport("advapi32.dll", CharSet=CharSet.Auto)]
public static extern int LogonUser(String lpszUserName,
String lpszDomain,
String lpszPassword,
int dwLogonType,
int dwLogonProvider,
ref IntPtr phToken);

public const int LOGON32_LOGON_INTERACTIVE = 2;
public const int LOGON32_PROVIDER_DEFAULT = 0;

void Login_Click(Object sender, EventArgs E)


{
IntPtr token = IntPtr.Zero;

if(LogonUser(UserName.Value,
UserDomain.Value,
UserPass.Value,
LOGON32_LOGON_INTERACTIVE,
LOGON32_PROVIDER_DEFAULT,
ref token) != 0)


{
FormsAuthentication.RedirectFromLoginPage(UserName.Value,
PersistCookie.Checked);
}
else


{
lblResults.Text = "Invalid Credentials: Please try again";
}
}
转载于:https://www.cnblogs.com/tingfeng/articles/488508.html