Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
helloo...

i want to save userid in session after that successfully login.
so any buddy can help me.
Posted

Try:

C#
Session["UserID"] = UserID;
 
Share this answer
 
Comments
rallecoding 25-Mar-19 9:48am    
This solution is simple, but effective, and good!
C#
// storing value in session
string firstName = "Jeff";
Session["FirstName"] = firstName;
//reading value from session
string firstName = (string)(Session["FirstName"]);
 
Share this answer
 
Assign value to Session after successful login

C#
Session["UserID"] = value;


here value can be anything like static or variable from Database....:)

like

C#
Session["UserID"] = 10;


or

C#
Session["UserID"] = Convert.toint32(DataTable1.Rows[0]["UserID"]);
 
Share this answer
 
Protected btnLogin_Click ()
{
//Write you logic here and verify user ID and Password.
if(Valid user)
{
Session["UserID"]= txtUserID.Text.Trim(); //txtUserID is your user id textbox id
}
else
{
Response.Redirect("~/Login.aspx",False);
}
}
 
Share this answer
 

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