Hi
Can anyone help me. I need to display the username in the lable of the masterpage. But I also have to show the logo of the business of the user. How should I do this!
Regards
Weppies

if you are using FormsAuthentication then
simple add Login View inside add Login Name..

once you are authenticated...it will display username

for more flexibility add Login Status control in login view
so user can signout..

and this whole thing is in master page ...so shared across all the pages

hope that helps

thanks for the help.Appreciate it
Regards Ernst

Re: Display user name in the header when logged in

a few seconds ago

when you validate the user, you can catch firstname in session then you can used it whatever you want it.

in code behind file where the login validation, something like this

internal bool ValidateUser(string userName, string passWord)
        {
            SqlConnection conn;
            string currentName = null;
            string firstname = null;

            //// userName must not be null
            if (null == userName)
            {
                return false;
            }

            //// passWord must not be null
            if (null == passWord)
            {
                return false;
            }

 try
            {                       
                //// connect to your  SQL Server.
                conn = DB connection string;
                string sqlUserName;
                string sqlfirstname;
                //// Create SqlCommand to select passwor and username fields from UserData table given supplied userName passWord.
                sqlUserName = "SELECT UserName,Password FROM [your table name] ";
                sqlUserName += " WHERE (UserName ='" + userName + "')";              
                sqlUserName += " AND (Password ='" + passWord + "')";               
                SqlCommand com = new SqlCommand(sqlUserName, conn);

                //// Create SqlCommand to select firstname and lastname fields from UserData table.
                sqlfirstname = "SELECT FirstName,LastName FROM [your table name] ";
                sqlfirstname += " WHERE (UserName ='" + userName + "')";             
                SqlCommand command2 = new SqlCommand(sqlfirstname, conn);
                    
                currentName = (string)com.ExecuteScalar();
                firstname = (string)command2.ExecuteScalar();
                //// Cleanup command and connection objects.
                conn.Dispose();
                conn.Close();
            }
            catch (Exception ex)
            {
                // Add error handling here for debugging.
                // This error message should not be sent back to the caller.
                System.Diagnostics.Trace.WriteLine("[ValidateUser] Exception " + ex.Message);
            }

            if (currentName != null)
            {
                Session["UserAuthentication"] = userName;
                Session["firstname"] = firstname;
                ////  Session.Timeout is set in web.config file.
                return true;
            }
            else
            {
                Session["UserAuthentication"] = string.Empty;
                return false;
            }
        }

then add this line of code to .aspx file you want to display the firstname. for example master.aspx

<div class="link" id="divid" style="float: right">
                            <asp:LoginName id="LoginName1" runat="server" />                      
                            </div>

and then add this line of code in the .cs file ex:(master.cs) under page_load.

protected void Page_Load(object sender, EventArgs e)
        {
            ////this can come from anywhere like session, database
            string firstname = (string)(Session["firstname"]);
            LoginName1.FormatString = "Sign in as" + " - " + firstname; ////output: Sign in as - username
        }

IS this helpful for you???????

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.