Display username instead of user id.

I have this?

FormsAuthentication.RedirectFromLoginPage(myUser.userID.ToString(), chkRememberPassword.Checked);

I need to display the username, but at the same time when I go to the default page
I acquire the userID. I can do myUser.UserName above. But I will need the ID to get the information about the user.

<asp:LoginView ID="LoginView" runat="server">
                              <AnonymousTemplate>
                                    <asp:HyperLink ID="LoginLink" runat="server" NavigateUrl="~/Members/Login.aspx">Login</asp:HyperLink>
                                    |
                                    <asp:HyperLink ID="RegisterLink" runat="server" NavigateUrl="~/Members/Registration.aspx">Register</asp:HyperLink>
                              </AnonymousTemplate>
                              <LoggedInTemplate>
                                    Welcome,
                                    <asp:LoginName ID="MemberName" runat="server" />
                                    |
                                    <asp:LoginStatus ID="MemberLoginStatus" runat="server" />
                              </LoggedInTemplate>
                        </asp:LoginView>


It displays the id instead of the username
 
 // Only attempt a login if all form fields on the page are valid
        if (Page.IsValid == true)
        {
 
            // Attempt to Validate User Credentials using CustomersDB
            string sSessionID = this.Session.SessionID;
 
            UserDB.UsersDB user = new UserDB.UsersDB();
            UserDB.UserDetails myUser = user.Login(txtUserName.Text, txtPassword.Text, sSessionID);
 
            if (myUser != null)
            {
 
 
                // Cookie with User Name
                if (!chkRememberPassword.Checked)
                {
                    // Store the user's fullname in a cookie for personalization purposes
                    Response.Cookies["UserName"].Value = myUser.sUserName;
                }
                else
                {
                    // Persist the cookie also up until 12:00AM since
                    // we need to allow user to rec points for loggin in
                    Response.Cookies["UserName"].Value = myUser.sUserName;
                    Response.Cookies["UserName"].Expires = DateTime.Now + new TimeSpan(365, 0, 0, 0);
                }
 
                //FormsAuthentication.SetAuthCookie(myUser.userID.ToString(),false);
                FormsAuthentication.RedirectFromLoginPage(myUser.userID.ToString(), chkRememberPassword.Checked);
 
 
 
 
            }
            else
            {
                FailureText.Text = "Login Failed!";
            }
 
        }

Open in new window

mathieu_cuprykAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

lucky_jamesCommented:
>> FormsAuthentication.RedirectFromLoginPage(myUser.userID.ToString(),
This will redirect to some other page and from this point onwards you want to display user name. Right?

Solution:
1. You have already put that in the cookie. All you need to do is to fetch that name from cookie.
2. You can also make use of query string while accessing the next page.
for more about query strings, check out:
http://msdn.microsoft.com/msdnmag/issues/07/03/CuttingEdge/

3. You can make use of Session variables in your code behind.

Hope it helps.

James
0
mathieu_cuprykAuthor Commented:
it's all nice to give me a link. But an explanation would be nice.
0
lucky_jamesCommented:
Your problem can be interpreted as the making available a data in later pages while the data fetch in a page navigated before.

let me explain it further:
you browsed a page A where you got data A. Now you want to get data A in the later pages you will be browsing through.

you can do it by 3 means:
1. Use a cookie. store the value in that cookie. later fetch the value from the same cookie.
2. Pass on to later pages a query string. it is something which gets appended in your url link in address bar.
3. use session variables. It is something like a bag of property which will remain till the session is there.

1 should not be followed as it comes up with a clause that users should keep the use of cookies enabled.

let me know if you need some more explanation.


James
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

mathieu_cuprykAuthor Commented:
Cookies enabled?
I can deal with session variables I just do not know how to populate.
I just do not know how to populate the following with the user name.
<asp:LoginName ID="MemberName" runat="server" />
                                    |
                                    <asp:LoginStatus ID="MemberLoginStatus" runat="server" />
instead of the userid.
0
lucky_jamesCommented:
you can put it as:
Session["your_session_variable_name"] = whatever_value;

check out:
http://www.exforsys.com/tutorials/asp.net-2.0/asp.net-2.0-customizing-the-session-state-mechanism.html

0
mathieu_cuprykAuthor Commented:
What I am trying to say is I do not know this control
<asp:LoginName ID="MemberName" runat="server" />
?
0
lucky_jamesCommented:
it is System.Web.UI.Page.User.Identity.Name

ok, so here is the problem u r facing:
you want to fetch the user name in web control. right?

you can put the value in this System.Web.UI.Page.User.Identity.Name control.

check out:
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.loginname.aspx
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mathieu_cuprykAuthor Commented:
I use it in
void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                UserDB.UsersDB user = new UserDB.UsersDB();

                SqlDataReader reader = user.GetUserInfo(Int32.Parse(Page.User.Identity.Name));

                while (reader.Read())
                {
                    lblUserName.Text = reader.GetString(1);
                    lblFirstName.Text = reader.GetString(2);
                    lblLastName.Text = reader.GetString(3);
                    lblZodiacSign.Text = reader.GetString(6);
                    lblAge.Text = reader.GetInt32(7).ToString();
                    lblGender.Text = (reader.GetInt32(8) == 0) ? "Male" : "Female";
                    lblDateOfBirth.Text = reader.GetDateTime(9).ToString("d");
                    lblLastOnline.Text = reader.GetDateTime(15).ToString();
                    lblLocation.Text =  reader.GetString(22).ToString() + ", " + GetCountryName(reader.GetString(19));


                }
            }

         
        }
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.