Getting the Liferay Session ID in Javascript


  • We can't extract the session ID using JavaScript, because the Liferay.ThemeDisplay.getSessionId() function consistently returns an empty string.


  • Liferay DXP 7.4


  • By default, the Liferay.ThemeDisplay.getSessionId() function will always return a blank string. To change this, you need to adjust your settings.
  • This is how you can resolve the issue:
    1. You need to set the property '' to 'true' within the file.
    2. Once this change is made, the session ID can be retrieved using the Liferay.ThemeDisplay.getSessionId() function.

Additional Information

  • While this solution will allow you to retrieve the session ID, it's crucial to understand the potential risk involved:
    • The '' property is usually set to 'false' to safeguard against potential security risks associated with session IDs being visible.
    • Keeping session identifiers in cookies is generally safer and more efficient.
    • This is because if a session ID is attached to a URL, there's a risk that if you share that URL, you could inadvertently share your session with the recipient if the code doesn't manage this scenario appropriately.
  • Follow the link for more information regarding Session Management in Liferay.
Este artigo foi útil?
Utilizadores que acharam útil: 0 de 0