Link to home
Start Free TrialLog in
Avatar of mathieu_cupryk
mathieu_cuprykFlag for Canada

asked on

Page.User.Identity.Name is readonly.

I want to put the username in the following:
 if (!Page.IsPostBack)
            {
                UserDB.UsersDB user = new UserDB.UsersDB();
               
                SqlDataReader reader = user.GetUserInfo(Int32.Parse(Page.User.Identity.Name));
                Page.User.Identity.Name = Response.Cookies["UserName"].Value;
                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));


                }
            }
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);
 
 
 
 
            }
--------------------------------------------------------------------
<LoggedInTemplate>
						Welcome,
						<asp:LoginName ID="MemberName" runat="server" />
						|
						<asp:LoginStatus ID="MemberLoginStatus" runat="server" />
					</LoggedInTemplate>
 
The userid comes up instead of the username.

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of vs1784
vs1784

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mathieu_cupryk

ASKER

Wat will happen if I get into this page? It requires the id/

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

                while (reader.Read())
This does not work it takes me back to login page instead of default.aspx
any other answers would be appreciated.