Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > ASP.NET > ASP.NET Authentication > ASP.NET User Authentication Active Directory (AD)



Clound SSD Virtual Server

ASP.NET User Authentication Active Directory (AD)

ASP.NET User Authentication Active Directory (AD) การใช้งาน ASP.NET กับ Authentication ผ่าน AD หรือ Active Directory

Language Code : VB.NET || C#

Code (VB.NET)
<%@ Assembly Name="System.DirectoryServices, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"%>
<%@ Import Namespace="System.DirectoryServices"%>
<%@ Import Namespace="System.Security.Cryptography"%>
<%@ Import Namespace="System.Text"%>
<%@ Page Language="VB" %>
<script runat="server">
	
	Dim initLDAPPath = "dc=tc, dc=thaicreate, dc=com"
	Dim initLDAPServer = "192.168.0.5"
	Dim initShortDomainName = "tc"
	Dim strErrMsg

    Public Function MD5(ByVal strString As String) As String
        Dim ASCIIenc As New ASCIIEncoding
        Dim strReturn As String
        Dim ByteSourceText() As Byte = ASCIIenc.GetBytes(strString)
        Dim Md5Hash As New MD5CryptoServiceProvider
        Dim ByteHash() As Byte = Md5Hash.ComputeHash(ByteSourceText)

        strReturn = ""

        For Each b As Byte In ByteHash
            strReturn = strReturn & b.ToString("x2")
        Next

        Return strReturn

    End Function

	Sub Page_Load(sender As Object, e As EventArgs) 
		

	End Sub

    Protected Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs)

		Dim DomainAndUsername As String = ""
        Dim strCommu As String
		Dim flgLogin As Boolean = False
        strCommu = "LDAP://" & initLDAPServer & "/" & initLDAPPath
        DomainAndUsername = initShortDomainName & "\" & txtUser.Text

        Dim entry As New DirectoryEntry(strCommu, DomainAndUsername, txtPwd.Text)
        Dim obj As Object

        Try

            obj = entry.NativeObject
            Dim search As New DirectorySearcher(entry)
            Dim result As SearchResult
            search.Filter = "(SAMAccountName=" + txtUser.Text + ")"
            search.PropertiesToLoad.Add("cn")
            result = search.FindOne()

            If result Is Nothing Then
                 flgLogin = False
				 strErrMsg = "Please check user/password"
            Else
                flgLogin = True
            End If

        Catch ex As Exception
              flgLogin = False
			strErrMsg = "Please check user/password"
        End Try
		

		IF flgLogin = True
			Me.lbDisplay.Text = "Welcome " & txtUser.Text
		Else
			Me.lbDisplay.Text = strErrMsg
		End IF
	End Sub
</script>

<html>
<head>
<title>ThaiCreate.Com AD/LDAP (Active Directory)</title>
</head>
 <body>
	<form id="form1" runat="server">
		<asp:TextBox ID="txtUser" runat="server" Width="147px"></asp:TextBox>
		<asp:TextBox ID="txtPwd" runat="server" Width="147px" TextMode="Password"></asp:TextBox>
		<asp:Button ID="btnLogin" runat="server" Text="Login" OnClick="btnLogin_Click" />
		<br />
		<asp:Label ID="lbDisplay" runat="server"></asp:Label>
	</form>
</body>
</html>







   
Share


ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท


ลองใช้ค้นหาข้อมูล


   


Bookmark.   
       
  By : ThaiCreate.Com Team (บทความเป็นลิขสิทธิ์ของเว็บไทยครีเอทห้ามนำเผยแพร่ ณ เว็บไซต์อื่น ๆ)
  Score Rating :  
  Create/Update Date : 2008-10-31 06:44:02 / 2010-07-09 22:18:03
  Download : No files
 Sponsored Links / Related

 
ASP.NET User Authentication and Login
Rating :

 
ASP.NET User Register Form
Rating :

 
ASP.NET User Authentication/Login Form
Rating :


ThaiCreate.Com Forum


Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   







Load balance : Server 02
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่