Función de cierre de sesión

I am using a windows form application where a login form (login prompt) is used to authenticate an user and then open the application. Let us assume that I have a default admin username and password for logging in. When I click the close button of the application or choose File--> Exit, I want logout to be implemented so that the user has to again log in using his credentials when he starts the application for the next time. I want this to take place using C#

Any help on this guys?

preguntado el 08 de noviembre de 11 a las 08:11

you neither provide enough details to help (like how is the login implement? DB? Session Management ? AD ?) not do you provide any source code of waht you have tried with a description what is not working... -

5 Respuestas

Normally,if you close the application its credientials will automatically go off. The application will start from stratch the next time you start.

In the scenario where the login session is carried over, do your logout tasks on FormClosing Evento o FormClosed Event; when the form is closed, the session will not carry over.

respondido 09 nov., 11:00

@Harish Kumar: Have you have used any kind of way for persisting the credentials (object persistance) ? If you have not done anything for persistance, just blindly close your app. When the form runs for next time it will start from stratch. - Madhana Kumar

i am not persisting the details Madhana. In that case, I think your words are true :) - Harish Kumar

Then its fine. Glad I could help :) - Madhana Kumar

You could implement logout actions inside the OnFormClosing() event handler of the form.

respondido 08 nov., 11:12

Your is user is authenticated only during the app start. If you will not implement some persistence mechanism to store the credentials or something like "cookie", then there's no need to deal with it - user will be prompted for credentials and authenticated on startup again.

respondido 08 nov., 11:12

Try logout on Form.Closing Event

respondido 08 nov., 11:12

is there a single line of code that would allow me t do that? Like application.logout() /?? - Harish Kumar

you can add event handler for FormClosedEventHandler and log off the user on that event.

consider SystemEvents.SessionEnded event and Form.Closing Events

respondido 08 nov., 11:13

is there a single line of code that would allow me to do that? - Harish Kumar

it depends on your login/logout implimentation - Damith

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.