Click here to Skip to main content
15,891,976 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
Hi All,
I am developing an application using asp.net, c#.net and SQL server.
I am using asp.net login controls(Login,LoginView and LoginStatus)

I want to use session for each User.
I want exact lines of code for assign session to user after login
and remove user from session once clicks Logout button.

Can anyone help me.
Thank you,
Posted
Updated 26-Feb-18 23:39pm
Comments
Sandeep Mewara 5-Jun-12 10:29am    
"I want exact lines of code for assign session..."
Are you paying us? That is extremely rude.
Sandeep Mewara 5-Jun-12 10:30am    
My vote of 1:
No effort and demanding.
dhiraj mane 15-Mar-14 8:15am    
No one is Prefect.... sandeep

 
Share this answer
 
Comments
jaipal0908 5-Jun-12 8:07am    
Can you please tell me the code once user login then If user clicks logout button how the session to be removed and what to write to redirect to login page after logout click.
Prasad_Kulkarni 5-Jun-12 8:20am    
You can use: Session.Abandon()

Or try this:
protected void btnLogout_Click(object sender, EventArgs e)
{
//clear session variables
Session["strIcaNo"] = "";
Session["strEmail"] = "";
Session["strName"] = "";
//redirect to login page
Response.Redirect("Login.aspx");
}


Have reference:
Browser back button issue after logout[^]

Clearing session after logout[^]
C#
Session.Add("username",HttpContext.Current.User.Identity.Name);
Session.Remove("username");
 
Share this answer
 
C#
protected void LogoutButton1_Click(object sender, EventArgs e)
    {
        Session.Abandon();	
	Session.Remove("Username");
        Session.Remove("Password");
        Response.Redirect("Login.aspx");
    }
 
Share this answer
 
Comments
Nelek 15-Mar-14 17:53pm    
Did you notice that the question is over 18 months old?

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