Click here to Skip to main content
16,020,182 members
Please Sign up or sign in to vote.
3.29/5 (3 votes)
See more:
Hi can Anybody give me an example for login page using sessions and how to implement sessions in login page and as well in the whole project
thanks in advance
Posted
Updated 18-Feb-11 5:14am
v2

Go here and pick an appropriate tutorial:

http://www.asp.net/web-forms[^]
 
Share this answer
 
Advice and examples of using Session have been posted many, many times. Before asking a question here at least spend a few minutes doing some research.

Anyway, from code behind add your value as:

Session.Add("key", "value");

and get it back as:

object value = Session["key"];

That should get you going.
 
Share this answer
 
Comments
Espen Harlinn 20-Feb-11 9:19am    
Good reply :)
C#
protected void btnlogin_Click(objec sender,EventArgs e)
{
Userclass u=new Userclass();
u.Username=txtusername.text.trim();
u.Password=txtpassword.text.trim();
if(u.checkUser())
{
Session["youreSessionName"]=u.Username;
Response.redirect("./Home.aspx")

}
else
{
lblIsUser.text=" User DOes not Exist";
}


you will use session["yoursessioname"] as a user name in the project for other information about the logged user from database or somewhere
 
Share this answer
 
v2
Ok.

Have a login page designed. On submit button click event have something like:
C#
{
  // Check for the authentication
  // if(authenticated)
  // {
  //    // Save the user profile/userid in a session.
  //    // Session["loggedInUserId"] = someId;
  // }
}


Whenever needed to verify or use the current loggedinId of the use, use Session["loggedInUserId"].ToString();
 
Share this answer
 
Comments
Espen Harlinn 20-Feb-11 9:18am    
My 5 :)
C#
protected void btnlogin_Click(objec sender,EventArgs e)
{
Userclass u=new Userclass();
u.Username=txtusername.text.trim();
u.Password=txtpassword.text.trim();
if(u.checkUser())
{
Session["youreSessionName"]=u.Username;
Response.redirect("./Home.aspx")
}
else
{
lblIsUser.text=" User DOes not Exist";
}

you will use session["yoursessioname"] as a user name in the project for other information about the logged user from database or somewhere
 
Share this answer
 
v2
Just write the following
C#
For create session   :::   session["username"]="The value you want to send";

receive session  :::   if(session["username"]!=null){
                        your variable=session["username"].ToString();
                        }
 
Share this answer
 
v2
crete session this way on login button click
Session["user"] = TextBox2.Text;
 
Share this answer
 
Comments
Omprakash Kukana 18-Sep-13 5:23am    
this is the most comm on way of use of session and you can use this methd then y u downvoted my ans

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