Click here to Skip to main content
15,891,725 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I would like to Logout the application in c#.net Windows application and login form should be opened at the time of Logout Can any one help
Posted
Updated 8-Jun-12 1:45am
v2
Comments
Sandeep Mewara 8-Jun-12 7:46am    
Logout in Winforms?
RDBurmon 8-Jun-12 8:25am    
Thanks Everyone who replied to this thread , So Anand, I think you have got enough response and you should be able to mark it as your answer and close the thread.
bbirajdar 8-Jun-12 9:40am    
Guys.. Op wants the answer for Winforms.. Not asp.net. He wants that when the click on 'Log out' button in the Windows app, then the login form should be displayed by default..

Use

Response.Redirect("login.aspx"); /
Clear previous session's, if you have any

Thanks,
SP
 
Share this answer
 
hi, If you are using FormsAuthentication then on Logout Button click write the following code
C#
Session.Clear();
Session.Abondon();
FormsAuthentication.SignOut();
Response.Redirect("Home.aspx");

and if you are not using FormsAuthentication then simply
C#
Session.Clear();
Session.Abondon();
Response.Redirect("Home.aspx");
will work.
 
Share this answer
 
Write the following logout code in logout button click event
C#
FormsAuthentication.SignOut();
Session["Name"].Abandon();
Response.Redirect("Login.aspx");

and in
login.aspx
page load event write the following statement.
XML
Response.Cache.SetNoStore();

it should be the first statement in the page load event.
if you are using the master pages then write the above statement in the master page load event.
 
Share this answer
 
Comments
Member 9217015 6-Jul-12 2:29am    
Sir I have a very simple question.i.e
Q1.How to match data from tables of MySql database in C# .net window application ?
Q2. Can we check login and logout time of a user/member? If yes then plZ help me....
Here is an article that shows you how to build a control that will do what you are asking (redirect the user to a login page when their session has timed out):

http://www.eggheadcafe.com/tutorials/asp-net/7262426f-3c65-4c90-b49c-106470f1d22a/build-an-aspnet-session-timeout-redirect-control.aspx[^]

There are other solutions, including simpler ones if that is what you are looking for, here:

http://forums.asp.net/p/1104278/1685530.aspx[^]
 
Share this answer
 
Simply use

C#
 Session.Abondon(); 
//and redirect user to login page.
Response.Redirect("Login.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