Click here to Skip to main content
15,906,624 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello developer! I am here for solving issue, I create my website in asp.net. And i maintain user session successfully, Now i am trying session id of login user. Mean a user create account on website after login he/she enter record in product table. i want when he enter his record his id also enter into the table of product record table to know which user enter that record. Please help me out

What I have tried:

 protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["username"] != null)
        {

            label1.Text =  Session.SessionID;
            Response.Write("welcome");



        }
        else
        {

            Response.Redirect("login.aspx");
        }
    }
    protected void TextBox2_Click(object sender, EventArgs e)
    {
        using (SuperFastEntities db = new SuperFastEntities())
        {
<pre lang="c#">

sample u = new sample();
u.name = sname.Text;



u.userID = Convert.ToInt32(Session["userID"]);

db.samples.Add(u);
db.SaveChanges();

}
}
Posted
Updated 24-Jul-20 10:56am
Comments
F-ES Sitecore 22-Jul-20 13:33pm    
The Session.SessionID isn't suitable for this as it isn't unique, it is reused among visitors. Instead create a GUID for your users and store that in Session["userID"]
Member 14879769 28-Jul-20 7:53am    
i did that but connection string was not in correct in well formate error shows me
Sandeep Mewara 23-Jul-20 9:57am    
What kind of authentication method you are using for login?
Member 14879769 28-Jul-20 7:53am    
username + password

1 solution

IF Session["username"] is unique then save that in your database table so you know who did it. An Id would be better than a name but some way to uniquely identify the user.
 
Share this answer
 
Comments
Member 14879769 28-Jul-20 7:55am    
username is unique and also that is already store in table, The issue is how can i store that user id in other table? which is login
ZurdoDev 28-Jul-20 8:09am    
Just write code to do it. Not sure where you are stuck.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900