function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jon Mountjoy_Jon Mountjoy_ 

How to log out?

Hi

 

I'm building in authentication using Customer Portal - and the Site class.  This provides methods for logging in, and registration.

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_sites.htm

 

However, I can't find out how to log out. There is no log out method.  How can I do that?

 

Thanks

Jon

Best Answer chosen by Admin (Salesforce Developers) 
BulentBulent

Jon,

 

there is no class for the logout. when you are logged in you are authenticated as portal user, and portal has a page for logout.

If you look at the out of the box sample SiteHeader component you can find the following line for the logout link for your pages

 

<apex:outputLink value="{!$Site.Prefix}/secur/logout.jsp" rendered="{!NOT(ISPICKVAL($User.UserType,'Guest'))}">{!$Label.site.logout}</apex:outputLink>

 

 

 

All Answers

BulentBulent

Jon,

 

there is no class for the logout. when you are logged in you are authenticated as portal user, and portal has a page for logout.

If you look at the out of the box sample SiteHeader component you can find the following line for the logout link for your pages

 

<apex:outputLink value="{!$Site.Prefix}/secur/logout.jsp" rendered="{!NOT(ISPICKVAL($User.UserType,'Guest'))}">{!$Label.site.logout}</apex:outputLink>

 

 

 

This was selected as the best answer
Chirag MehtaChirag Mehta
Is there any option to perform a silent logout i.e., invoke the logout action without the need to click on any "Logout" link?
Chirag MehtaChirag Mehta
How about retuning PageReference with value of "{!$Site.Prefix}/secur/logout.jsp" or is there any better approach ?
patrospatros

I can't seem to get this to actually work in a Force.com Site.

 

For starters, {!$Site.Prefix}/secur/logout.jsp returns a 404 error when I try to create a link in the context of my site.

 

And, if I try to hard-link to anything like naX.salesforce.com/secure/logout.jsp, it routes me to the standard SF logout but when I return to my site I'm still logged in as a specific user.

BulentBulent

I just tested and it works (<a href="{!$Site.Prefix}/secur/logout.jsp">Logout</a>).

you need to set the logout url to the page that you want to navigate after logout. This is a field on your portal setup page. 

Chirag MehtaChirag Mehta

Earlier the logout.jsp was working, but the sid(cookie) was not getting purged(deleted). This resulted in not able to re-login in saying an error "user is already logged in"

 

So found one more setting. Also you need to set "New User Form URL" Customer Portal Setting. For me once I set this, then after logouts the cookie is purged and i am able to re-login without any already logged in error.

kprkpr

Hi Chirag, 

 

Were you able to find a way to perform a silent logout? What about the pagereference?I was able to log out using the pagereference, but I want to redirect the user to the login page after this. Is there a way to do this?

 

Thanks in advance,

kpr

temp1.392782059108939E12temp1.392782059108939E12
Thanks, I tested and ran ok.