• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 950
  • Last Modified:

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

0
mathieu_cupryk
Asked:
mathieu_cupryk
  • 3
1 Solution
 
vs1784Commented:
Page.User.Identity.Name = Response.Cookies["UserName"].Value;

This is wrong.

If you want to set value of logged in user then set this

FormsAuthentication.SetAuthCookie(myUser.userID.ToString(),false);


Hope it helps.

Thanks
0
 
mathieu_cuprykAuthor Commented:
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())
0
 
mathieu_cuprykAuthor Commented:
This does not work it takes me back to login page instead of default.aspx
0
 
mathieu_cuprykAuthor Commented:
any other answers would be appreciated.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now