Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
what is the coading for logout ?
Posted

Try:
C#
/// <summary>
/// Log in / log out - as appropriate
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void butLogInOut_Click(object sender, EventArgs e)
    {
    if (User != null)
        {
        FormsAuthentication.SignOut();
        Session["UserId"] = null;
        Response.Redirect(@"~\Default.aspx", true);
        return;
        }
    Response.Redirect(@"~\Login.aspx", true);
    }

Or (crude, but it will work):
C#
Session.Abandon();
Response.Redirect("~/Default.aspx");
 
Share this answer
 
Comments
Janardan Pandey 20-Dec-11 4:07am    
thanks i will try it in my web page.
RaviRanjanKr 20-Dec-11 4:13am    
My 5+
Hi,


If you are using session means, clear the session values and redirect to login page, in logout button click..

C#
Session.Clear();Response.Redirect("login.aspx");


or use the below code to clear session values.


C#
Session.Abandon();
 
Share this answer
 
v3
Comments
Janardan Pandey 20-Dec-11 4:07am    
Thank u i will try it.
RaviRanjanKr 20-Dec-11 4:13am    
My 5+
Shobana16 20-Dec-11 4:24am    
Thank u..
Google?

Abandon the session & redirect to login page, that's all.
C#
protected void LogOut()   
{       
     Session.Abandon();       
     Response.Redirect("Login.aspx");
}
 
Share this answer
 
Comments
Janardan Pandey 20-Dec-11 4:07am    
Thank u i will try it.
RaviRanjanKr 20-Dec-11 4:13am    
My 5+
Try at click event of logout button
C#
Session.Abandon();
Session.Contents.RemoveAll();
System.Web.Security.FormsAuthentication.SignOut();
Response.Redirect("../yourDefaultPage.aspx");
 
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