ASP.NET FormsAuthentication – Logout
protected void LoggedOut(object sender, EventArgs e)
{
FormsAuthentication.SignOut();
HttpCookie authCookie = Context.Response.Cookies.Get(FormsAuthentication.FormsCookieName);
if (authCookie != null)
authCookie.Expires = DateTime.Now.AddYears(-1);
Session.Abandon();
Response.Redirect("~/default.aspx", true);
}
Mit diesem Code wird verhindert man, das eine Applikation mehr als einmal innerhalb einer Session (Anmeldung) ausgeführt werden kann:
private const string AppGuid = "97E652FF-73A5-3ED6-A4E5-DA2AF2132C98";
[STAThread]
private static void Main()
{
using (Mutex progMutex = new Mutex(false, AppGuid))
{
if (!progMutex.WaitOne(0, false))
{
MessageBox.Show("Dieses Programm ist bereits geöffnet");
return;
}
Application.Run(new Form1());
}
}
Soll die Anwendung in allen Sessions nur einmal ausgeführt werden können, muss man den Mutex in den global Namespace schreiben:
private const string AppGuid = "97E652FF-73A5-3ED6-A4E5-DA2AF2132C98";
[STAThread]
private static void Main()
{
using (Mutex progMutex = new Mutex(false, @"Global\" + AppGuid))
{
if (!progMutex.WaitOne(0, false))
{
MessageBox.Show("Dieses Programm ist bereits geöffnet");
return;
}
Application.Run(new Form1());
}
}