在asp.net中登录域

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";
}

}
posted @ 2006-08-28 16:08  快乐的老毛驴  阅读(248)  评论(0编辑  收藏  举报