Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How can i convert a asp VB script into a asp.net VB script.

Posted on 2008-10-17
2
Medium Priority
?
410 Views
Last Modified: 2011-09-20
What this script does is it shows the user account that is logged on and there phone number from active directory.

I have this code working in asp.
but i cannot get the code to work in asp.net

Can someone help me out.
<%@ LANGUAGE=VBSCRIPT %>
<%Option Explicit%>
 
<%
 ' Check to see if the session variable is already populated.
  If Session("LOGON_USER") = "" Then
    ' Check to see if the user has logged on at all.
    If Request.ServerVariables("LOGON_USER") = "" Then
      ' Force authentication if not.
      Response.Clear
      Response.Status = "401 Access Denied"
      Response.End
    Else
      ' Store the client's user name in a session variable.
      Session("LOGON_USER") = Request.ServerVariables("LOGON_USER")
      ' Strip out an NT domain from the user name.
      If InStr(Session("LOGON_USER"),"\") then
                    Session("LOGON_USER") = Mid(Session("LOGON_USER"), InStr(Session("LOGON_USER"), "\") + 1)
 
      End If
    End If
  End If
Function getADUserInfo(strUID)
        on error resume next
        strGeneralLookupError = false
    strBase = "<LDAP://DC=[domain], DC=[domain ext ie local or com]>"
        strFilter = "(sAMAccountName=" & strUID & ")" 
        strAttributes = "cn, mail, company, givenName, sn, ADsPath, name, sAMAccountName, telephoneNumber"
        'strAttributes = "cn, company, givenName, sn, ADsPath, name, sAMAccountName, telephoneNumber"
        strScope = "subtree"    
        strFullCommand = strBase & ";" & strFilter & ";" & strAttributes & ";" & strScope
        set rsADUserInfo = Server.CreateObject("ADODB.Recordset")
        set     rsADUserInfo = connAD.Execute(strFullCommand)
        if err.number <> 0 then
                strGeneralLookupError = true
        end if
        set getADUserInfo = rsADUserInfo
        set rsADUserInfo = Nothing
End Function
 
Sub getUserData(p_strUserID)
        on error resume next
        set rsUserData = Server.CreateObject("ADODB.Recordset")
        set rsUserData = getADUserInfo(p_strUserID)
        if not rsUserData.EOF then
                strUserGN = rsUserData("givenName")
                strUserSN = rsUserData("sn")
                strUserOU = rsUserData("company")
                strUserEmail = rsUserData("mail")
                strUserPhone = rsUserData("telephoneNumber")
        else
                strADLookupSuccess = false
        end if
        rsUserData.Close
        set rsUserData = Nothing
End Sub
 
on error resume next
 
response.expires = 0
 
DIM connAD, rsUserData, rsADUserInfo
DIM strUserGN, strUserSN, strUserOU, strUserEmail, strUserPhone
DIM strBase, strFilter,strAttributes, strScope, strFullCommand
DIM strGeneralLookupError, strADLookupSuccess
DIM strUserID
 
strUserGN = "The user can not be found in the system."
strGeneralLookupError = false
strADLookupSuccess = true
 
set connAD = Server.CreateObject("ADODB.Connection")
connAD.Provider = "ADsDSOObject"
connAD.Properties("User ID") = "[domain]\[user account]" ' ### remember to make sure this user has rights to access AD
connAD.Properties("Password") = "[password]"
connAD.Properties("Encrypt Password") = true
connAD.Open
 
strUserID = Session("LOGON_USER")
call getUserData(strUserID)
 
connAD.Close
set connAD = Nothing
%>
 
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>ASP Code to access AD with LDAP Page</title>
</head>
<body>
<%=strUserGN%> 
<%=strUserSN%><br />
<%=strUserOU%><br />
<%=strUserEmail%><br />
<%=strUserPhone%><br />
</body>
</html>

Open in new window

0
Comment
Question by:phoenixfire425
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 7

Accepted Solution

by:
maXXXeE earned 500 total points
ID: 22739954
For a start, asp.net uses VB.Net or C# and not VBScript.

ASP.Net is a very different thing compared to  ASP 3(or classic asp), u cant just copy the asp3 code and get it running.

u could check out this url
http://www.startvbdotnet.com/aspsite/asp/
0
 
LVL 6

Author Comment

by:phoenixfire425
ID: 22950035
Thank you that was a little useful
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question