Print this page

Community - web tab not working properly when login is enabled

Knowledge Article Number 000205558
  1. Create a community
  2. Prepare community to enable login
  3. Open to add a page
    1. Force site to use authentication
    2. Assume that URL of this page is "community/s/page.html")
  4. Open web tab (URL looks like /servlet/servlet.Intgration?lid=01ri0000000pk2m) as anonymous user
  5. You should be prompted with login information
  6. Login as community user
  7. You will the iFrame part (as it's web tab) refresh but not entire page so there are no tabs until entire page is manually refreshed
    1. iFrame URL is "community/s/page.html"

This is normal behavior because form is submitted inside iFrame but parent page is not refreshed. There is a workaround for this as below:
  1. Change <apex:form> tag on your login page to add target="_top" 
    1. This will ensure that form is submitted in parent window rather than just iFrame
  2. In Login controller, you can Apex code mentioned at the end
  3. Code will check for refUrl which will be the original page ( /servlet/servlet.Intgration?lid=01ri0000000pk2m)
  4. startUrl will be "community/s/page.html" as that is what the above servlet resolves to (web tab)
  5. Code should check
    1. if refUrl exists then redirect users to that page
      1. ​Need to remove domain part from the URL as site.login() does not redirect to absolute URL
    2. if not and startUrl exists then redirect users to that page
    3. If not then redirect users to baseUrl for site
Note: This is sample code only. Please make sure to test this code to ensure it is working as expected. This code hasn't been tested for all conditions
global PageReference login()
	//Get refUrl
	String strRefUrl = System.currentPageReference().getParameters().get('refURL'); 

	//Get startUrl
	String strStartUrl = System.currentPageReference().getParameters().get('startURL'); 

	//if refUrl is not empty then redirect users to this URL
	if(strRefUrl != null && strRefUrl != ''){ 

		//Need to remove domain part because site.login() does not redirect to absolute URL
		strStartUrl  = strRefUrl.replace(Site.getBaseUrl (),''); 

	}else if(strStartUrl == null || strStartUrl == ''){ 
		//Redirect to base URL if refUrl AND startUrl are empty
		strStartUrl = Site.getBaseUrl (); 

	return Site.login(username, password, strStartUrl ); 


promote demote