Login and retrieve UserName with email and password in ASP.Net

Last Reply on Jun 25, 2018 12:37 AM By micah

Posted on Jun 24, 2018 11:47 PM

Hi i use email and password to login and on landing page i use the email fetched to enter data. But on second page i want to display data using usernames, so that means that i have to insert username while inserting email as well in landing page insert. this is wht i use to fetch the email

HttpContext.Current.User.Identity.Name

then insert it this way

getADPOST = "Insert INTO USERPost (UserName,Email,Description) values (@UserName,@Email,@Description)";
cmd.Parameters.AddWithValue("@Description", Textpost.Text.Replace(Environment.NewLine, "<br/>").Trim());
cmd.Parameters.AddWithValue("@Email", HttpContext.Current.User.Identity.Name);

but i need to insert username as well without session

getADPOST = "Insert INTO USERPost (UserName,Email,Description) values (@UserName,@Email,@Description)";
                                
cmd.Parameters.AddWithValue("@Description", Textpost.Text.Replace(Environment.NewLine, "<br/>").Trim());
cmd.Parameters.AddWithValue("@Email", HttpContext.Current.User.Identity.Name);
cmd.Parameters.AddWithValue("@UserName", username1);

Note: the idea is, i want to display data using username on second page but use email wjich i used in login to insert on home page, so any idea on how to solve this problem?

Posted on Jun 25, 2018 12:37 AM Modified on on Jun 25, 2018 12:46 AM

sorry this is the formular that i used and it just worked now, i used this to fetch data in the other page were i want to fetch data using usernames

 procedure

FROM USERPost WHERE UserName=@Email 

 code behind

con.Open();
using (SqlCommand cmd = new SqlCommand(getADPOST, con))
{
    cmd.CommandType = CommandType.StoredProcedure;
    {
        cmd.Parameters.AddWithValue("@Email", HttpContext.Current.User.Identity.Name);