RhythmAddict112
Programmer
Hey all..I'm new to .net, so please bear with me. I have a function written in classic ASP that grabs some basic info (name, email address) from AD given a username...I need to get this working in asp/vb.net but it's driving me crazy. I have tried this tutorial however I receive an error stating I need to end Public Class Default, however doing so just brings forth another error ( Compiler Error Message: BC30451: Name 'HttpContext' is not declared. ) Does anyone have a working sample of some simliar ADSI code? The code I'm tryin to use from the FAQ follows..any direction here would be great.
Use your resources, you're on the internet!
Code:
Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.DirectoryServices
Public Class _Default
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents lblUserName As System.Web.UI.WebControls.Label
Protected WithEvents Table1 As System.Web.UI.WebControls.Table
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents Label2 As System.Web.UI.WebControls.Label
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
SetupSession()
End Sub
Sub SetupSession()
Dim strUserName As String
Dim strRealName As String
Dim strADPath As String
'strUserName = HttpContext.Current.User.Identity.Name
strUserName = "DOMAIN1\GREEN"
strUserName = strUserName.Replace("DOMAIN1\", "")
'strADPath = "DC1.DOMAIN1.com"
Dim Entry As DirectoryEntry = New DirectoryEntry("LDAP://" & strADPath, "DOMAIN1\GUEST", "GUESTPWD5")
Dim Searcher As DirectorySearcher = New DirectorySearcher(Entry)
Dim result As System.DirectoryServices.SearchResult
Try
Searcher.Filter = ("(anr=" & strUserName & ")")
result = Searcher.FindOne()
strRealName = (result.GetDirectoryEntry().Name).Replace("CN=", "").Replace("\", "")
Catch ex As Exception
Dim debug As String = ex.Message
End Try
End class
Use your resources, you're on the internet!