Click here to Skip to main content
15,568,965 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I'm a complete Newbee on C# sharp, a real freshman so to speak and I could definitely use some help.

I've Managed to create a very basic website, using Webforms with Visual C#. I'm using Visual Studio 2010 and .NET 3.5.

For this site I created a Master page, on which all my Web Forms will be based. On every webform I want to display the username and the e-mail address of the users who will be accessing my site.

But I don't have any clue whatsoever how to perform a AD query from my Masterpage.master

Beneath is what I created so for.
- So where should I query AD?
- How would the code look like?
- Can I use my Toolbox for this?
- Username should be displayed at USer_Name (see code beneath)
- E-MailAddress should be displayed at E-Mail_adres (see code beneath)

XML
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <asp:ContentPlaceHolder id="head" runat="server">
    </asp:ContentPlaceHolder>
    <style type="text/css">
        .style1
        {
            width: 100%;
            height: 140px;
        }
        .style4
        {
            width: 107px;
            margin-left: 40px;
        }
        #form1
        {
            height: 545px;
        }
        .style10
        {
            font-family: "Times New Roman", Times, serif;
            color: #3333FF;
            font-size: xx-large;
            font-weight: 700;
        }
        .style11
        {
            width: 30%;
        }
        .style12
        {
            width: 18%;
            float: left;
        }
        .style13
        {
            width: 80%;
            float: right;
        }
        .style14
        {
            color: #3333FF;
        }
        .style15
        {
            width: 0%;
            float: left;
            height: 291px;
        }
        .style16
        {
            color: #000000;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table class="style1">
            <tr>
                <td class="style4">
                    <asp:Image ID="Rabobank" runat="server" Height="125px"
                        ImageUrl="~/Images/xyz.png" Width="98px" />
                </td>
                <td class="style10" height="2">
                    <strong>Any Device Portaal</strong></td>
                <td class="style10" height="2">
                    <asp:ContentPlaceHolder ID="Sub_Titel" runat="server">
                    </asp:ContentPlaceHolder>
                </td>
                <td>
                    <asp:Image ID="Image1" runat="server" Height="126px" ImageAlign="Right"
                        ImageUrl="~/Images/SmartPhones.jpg" Width="115px" />
                </td>
            </tr>
        </table>
    </div>
    <asp:Panel ID="Panel1" runat="server" BackColor="#3333FF" BorderColor="#3333FF"
        ForeColor="#3333FF" Height="3px">
        <hr />
    </asp:Panel>
    <br />
    <table align="right" class="style11">
        <tr>
            <td>
                Gebruikersnaam:</td>
            <td>
                USer_Name</td>
        </tr>
        <tr>
            <td>
                E-Mail adres</td>
            <td>
                E-Mail_adres</td>
        </tr>
    </table>
    <br />
    <br />
    <br />
    <table align="left" class="style12">
        <tr>
            <td style="text-decoration: underline; font-weight: 700">
                <span class="style14">Handige Links:</span><br />
                <asp:HyperLink ID="HyperLink_Main_01" runat="server">ICT_Services</asp:HyperLink>
                <br />
                <asp:HyperLink ID="HyperLink_Main_02" runat="server">Blog</asp:HyperLink>
                <br />
                <asp:HyperLink ID="HyperLink_Main_03" runat="server">Manuals</asp:HyperLink>
                <br />
                <br />
                <span class="style14">Navigatie Any Device:<br />
                </span>
                <asp:HyperLink ID="StartPagina_StartPagina" runat="server" CssClass="style16"
                    NavigateUrl="~/Default.aspx">Start Pagina</asp:HyperLink>
                <br />
                <asp:HyperLink ID="StartPagina_Got_Problem" runat="server"
                    NavigateUrl="~/Got_Problem.aspx" style="color: #000000">Problemen met mijn toestel</asp:HyperLink>
                <asp:ContentPlaceHolder ID="HyperLinks" runat="server">
                </asp:ContentPlaceHolder>
            </td>
        </tr>
    </table>
&nbsp;&nbsp;
    <table align="left" class="style15">
        <tr>
            <td bgcolor="#3333FF">
                &nbsp;</td>
        </tr>
    </table>
&nbsp;<table align="right" class="style13">
        <tr>
            <td>
                <asp:ContentPlaceHolder ID="Main_Title" runat="server">
                </asp:ContentPlaceHolder>
                <asp:ContentPlaceHolder ID="Main_Body" runat="server">
                </asp:ContentPlaceHolder>
            </td>
        </tr>
        <tr>
            <td>
                &nbsp;</td>
        </tr>
    </table>
&nbsp;&nbsp;
    </form>
        <div id="footerContent">
        2011 xyz. Alle rechten voorbehouden.
        <br />
        Any Device is onderdeel van abc</div>
</body>
</html>
Posted

1 solution

You can take Lables[^] to display username and email address. And try these to get user details from active directory:

How to get User Data from the Active Directory[^]

http://stackoverflow.com/questions/637486/how-to-get-the-current-users-active-directory-details-in-c-sharp[^]

hope it helps :)
 
Share this answer
 
v2
Comments
Joliet_Jake 24-Nov-11 15:41pm    
Hi Uday,

First of all, thanks a lot for trying to help me out here.

I previously found the link ("How to get user Data from Active Directory")you're sending me, but I don´t understand it.

My biggest problem is, how to get stuff like this into my current code and where. Where should I put the the code in the web-form, do I have to place it between tags or something=

Please forgive me for being so ignorant, it´s just my first C#, normally I´m occupied with Exchannge Active Sync and stuff like that.

Cheers
Jan

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900