Use domain user logon in Asp.net Application

Source: Internet
Author: User

From: http://weblogs.3322.org/
The current program requires that the Asp.net program can use existing domain users to log on (and be sure to use forms to log on in order to be consistent with other program interfaces ), you can find some relevant information and find it.

Mainly depends onThe logonuser API function in advapi32.dll. 

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 use are not much different from common forms programs, and there may be better methods.

Note: technology consistency

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.