How to check if backend user is logged in?

I have a customer that wants an adminbar to appear on their webpage if they are logged into the backend. I am trying to do this from an UmbracoViewPage, and after some googling, I’ve found the two following solutions, however they don’t seem to work:

 bool isLoggedIn = UmbracoContext.Security.IsAuthenticated();

This always returns false.

bool isLoggedIn = UmbracoContext.Security.CurrentUser != null;

CurrrentUser is always null.

Any help would be appreciated!


This is a companion discussion topic for the original entry at https://our.umbraco.com/forum/98670-how-to-check-if-backend-user-is-logged-in