Dynamic Hyperlinks or Conditional Hyperlinks

Posted on 2008-11-18
Last Modified: 2012-06-22
I am trying setup a page that has a "conditional" link or dynamic link.
I may not be using the proper name for it so i will tell you what i am trying to do.

The page i have has the Active Directory connector on it. and what i want to happen is this.

If a user from the the executive member group logs on i want the continue link to goto the "executive" page.
and if a normal user logs on then i want it to goto their page.

Attached is my asp code.

i dont know if i can use an "IF" statement or not.


<%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.Status = "401 Access Denied"



      ' 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=diamed, DC=local>"

	strFilter = "(sAMAccountName=" & strUID & ")" 

	strAttributes = "cn, mail, company, givenName, sn, ADsPath, name, sAMAccountName, telephoneNumber, physicalDeliveryOfficeName"

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

		strUserOF = rsUserData("physicalDeliveryOfficeName")

		strUserEmail = rsUserData("mail")

		strUserPhone = rsUserData("telephoneNumber")


		strADLookupSuccess = false

	end if


	set rsUserData = Nothing

End Sub

on error resume next

response.expires = 0

DIM connAD, rsUserData, rsADUserInfo

DIM strUserGN, strUserSN, strUserOU, strUserEmail, strUserOF,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") = "diamed0\administrator" ' ### remember to make sure this user has rights to access AD

connAD.Properties("Password") = "*********"

connAD.Properties("Encrypt Password") = true


strUserID = Session("LOGON_USER")

call getUserData(strUserID)


set connAD = Nothing


<style type="text/css">


.style1 {

	font-size: 36px;

	font-weight: bold;


.style2 {font-size: 24px}



<div align="center">

  <h1><script type="text/javascript">

var d = new Date();

var time = d.getHours();

if (time < 11) 


document.write("<b>Good morning</b>");


if (time > 5) 


document.write("<b>Good Evening</b>");




document.write("<b>Good Afternoon</b>");



    <br />

    <br />

  Welcome To REPCOM</h1>


                    class="style6"><%=strUserSN%><br /></h1>

  Your Assigned Rep Number is <%=strUserOF%>


<p align="center" class="style1">&nbsp;</p>

<table width="253" border="1" align="center" bordercolor="#0000FF">


    <td width="243"><div align="center"><span class="style1"><a href="/repcom/Users/<%=UCase(Session("LOGON_USER"))%>/index.asp" class="style2">Click Here To Login</a></span></div></td>



<p align="center" class="style1">&nbsp;</p>

<p align="center">&nbsp;</p>

<p align="center">&nbsp;</p>

<p align="center">&nbsp;</p>

<p align="center"><a href="Users/general/Index.asp">General Access</a></p>

<p align="center"><a href="/Repcom/Template/Index.asp"><strong>Executive Access</strong></a><br />


Open in new window

Question by:phoenixfire425
    LVL 23

    Expert Comment

    How do you determine the user is an executive, I don't se any code for that?

    Once you have determined that you should be able to do an IF

    I also don't see a continue link? Are you talking about the two links at the bottom?
    <% If Session("EXECUTIVE") Then %>
    <p align="center"><a href="/Repcom/Template/Index.asp"><strong>Executive Access</strong></a>
    <% Else %>
    <p align="center"><a href="Users/general/Index.asp">General Access</a></p>
    <% End If %>

    Open in new window

    LVL 6

    Author Comment

    Well I am trying now to pull in the "member of" for the user now.  So its not in there yet.

    I cant seem to figure out a way to have it find out if the user is a part of the Executive group or the Non-Executive group.  Any ideas?
    LVL 23

    Accepted Solution

    This is more of an asp and Active Directory problem.

    You may get more help if to re-assign it to those zones.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Introduction HyperText Transfer Protocol ( or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
    New Relic: Our company recently started researching several products to figure out what were the best ways for us to increase our web page speed and to quickly identify performance problems that we may be having. One of the products we evaluated wa…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
    Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now