Portal Engine Questions on portal engine and web parts.
Version 6.x > Portal Engine > Programatically log out user but Kentico user is still logged in View modes: 
User avatar
Member
Member
bukanbaka2-hotmail - 9/7/2012 4:27:18 AM
   
Programatically log out user but Kentico user is still logged in
Hi,

I got a problem where when a user click on log out button from the cms desk or cms site manager, user is redirected to home page but still is logged in.

I have customized the code
/cmsdesk/header.aspx.cs

where the method below is the original,


protected void btnSignOut_Click(object sender, EventArgs e)
{
// Usual sign out
string signOutUrl = URLHelper.ApplicationPath.TrimEnd('/') + "/default.aspx";

// LiveID sign out URL is set if this is LiveID session
SignOut(ref signOutUrl);

ltlScript.Text += ScriptHelper.GetScript("parent.location.replace('" + signOutUrl + "');");
}


I have customized it to point to another page called KenticoSignOut.aspx


protected void btnSignOut_Click(object sender, EventArgs e)
{
// Usual sign out
string signOutUrl = URLHelper.ApplicationPath.TrimEnd('/') + "/KenticoSignOut.aspx";

// LiveID sign out URL is set if this is LiveID session
//SignOut(ref signOutUrl);

ltlScript.Text += ScriptHelper.GetScript("parent.location.replace('" + signOutUrl + "');");
}



In my KenticoSignOut.aspx.cs (placed on the root folder of the website), I have


protected void Page_Load(object sender, EventArgs e)
{
FormsAuthentication.SignOut();
CMSContext.CurrentUser = null;
Response.Cache.SetNoStore();
Response.Redirect("~/default.aspx");
}


Somehow, despite the code in KenticoSignOut.aspx.cs run, but it didn't work as expected.
Sometimes user still remain logged in.

Is there something I'm missing?

Thanks.

User avatar
Kentico Customer Success
Kentico Customer Success
kentico_martind2 - 9/7/2012 5:09:31 AM
   
RE:Programatically log out user but Kentico user is still logged in
Hi,

the best way to learn how Log Out is working is to take a look at the code of it.
Look whats happening behind the default LogOut (SignOut) button: your_site\CMSWebParts\Membership\Logon\SignOutButton.ascx.cs

What you've done is only setting some parameters, but the "magic" (setting cookie etc.) is happening when you click the LogOut button in SignOut handler.
Look in the SignOutButton.ascx.cs for the code of method: protected void btnSignOut_Click()...