Display differnt links to different users

Posted on 2005-05-12
Last Modified: 2010-04-07
I would like some help on how can I displat different links to different user.

Ex. If you go to my website, you should not be able to see the link edit profile, unless you login. And I have 2 differents type of user, and they should have different links.

I'm using access db.
Question by:Ennio
    LVL 24

    Accepted Solution

    The first is usually done by using a different header within the secure folder (i.e. the one that contains the pages users access after they've logged in).

    The second will require dynamically setting the links on the header. You can do this simply enough by creating all the links for both of the users in the header, and hiding the links you don't want when the header (ascx file) loads.
    LVL 1

    Author Comment

    So I got a book here but It's not a good one..

    So I should create a ascx file for each one action I want to happened (like if a user is a guest do not display any link, if the user is level 1 display some link,etc...)
    LVL 14

    Assisted Solution

    In this case I'd use some table to contain ALL of the links you're using. It would consis of four columns: ID Name URL Group. If link is accessible only by group #1 then Group column would contain value 1, if link is accessible only by group #2 then Group column would contain value 2 and if link is accessible for both groups Group colmun would contain value 3.

    Then, in a mentioned above webusercontrol (ascx) I'd place datagrid(or datalist) whitch would contain a template column with a Hyperlink WebControl in it. The last thing to do is to select links from a table depending on a visiting user's group and to bind the selected recordset to datagrid. Hyperlink's NavigateUrl ant Text properties would reflect Tables Name and URL columns' values respectivelly.

    Hope this will help
    LVL 25

    Assisted Solution

    The question is why you want to show two different URL to users?  If user has two different role assingned you should better append a variable int he querystring and based on that call the apporpriate funcitons.

    For example:

    When administrator logs in define a Session variable access level in the login page:

    Session["USER_ROLE"] = "ADMIN";

    When a normal user logs in:

    Session["USER_ROLE"] = "USER";

    Now in the URL:

    <a href="MyProfile.aspx?UserID=1&UserRole=<%=Session["USER_ROLE"]%>">Profile</a>

    You should be able to achive the functionality in this way rather than defining the URL for a user in the database.  This approach will also add a consistency to your application.

    HTH, Nauman.
    LVL 1

    Author Comment

    I'm getting this error using .ascx file

    I have a page_load that need to popula some fields that are in my .ascx file (CAN I DO THAT?)

    I'm posting my codes here.

    My .ASCX file (this is just a test, so I only have these 2 fields)

    First Name: <asp:TextBox ID="txtfname" runat="server" /><br />
    Last Name: <asp:TextBox ID="txtlname" runat="server" /><br />


    My aspx page

    <%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
    <%@ Register TagPrefix="bsf" TagName="babysitterform" src="babysitter.ascx" %>
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.OleDb" %>
    <%@ Import Namespace="System.Web.Security" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
    <script language="vb"  runat="server">
    Sub Page_Load( S As Object, E As EventArgs)
          If Not isPostBack Then
                Dim myConn As OleDbConnection
                Dim myComm As OleDbCommand
                Dim myData As OleDbDataReader
                myConn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("/database/babysitter.mdb") & ";")
                babysitterform1.txtfname.Text = "Ennio"
          End If
    End Sub
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    <form runat="server">
    <bsf:babysitterform ID="babysitterform1" runat="server" />

    LVL 1

    Author Comment

    and here is the error

    Compilation Error
    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: BC30390: '_ASP.babysitter_ascx.txtfname' is not accessible in this context because it is 'Protected'.

    Source Error:


    Line 7:              myConn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("/database/babysitter.mdb") & ";")
    Line 8:              myConn.Open()
    Line 9:              babysitterform1.txtfname.Text = "Ennio"
    Line 10:             
    Line 11:             myConn.Close()

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    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

    19 Experts available now in Live!

    Get 1:1 Help Now