Thursday, September 2, 2010

ASP.net Application using domain user login

Now make a program that ASP.net program Ke Yi Yao Qiu use the existing domain user Lai log (Erqieweile consistent with other procedures Jiemian to use Forms Login Yi Ding), find a number of related to Ziliao found Haishi can be realized. Mainly rely on advapi32.dll LogonUser API function in. using System.Web.Se ...
Now required to do a program in ASP.net program can use existing domain user to log in (and in order to interface with other programs, Yi Zhi sure to use Forms login), find some relevant information found or can be realized.
Mainly rely on advapi32.dll LogonUser API function in.



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

)

)

Other aspects of the use and common forms program is not much different, and perhaps a better way.

No comments:

Post a Comment