Search code examples
c#.net-4.0umbraco

How to check if user is logged on, Not Member?


Have tried 2 different methods to check if the user is logged into Umbraco Administration from the front-end in a User Controls Code-Behind (.cs) file:

Page.User.Identity.IsAuthenticated

and

umbraco.library.IsLoggedOn()

Both of these always returns false, even when I am logged in. How to check if user is logged in correctly?? Trying to get this on the front-end. Is there a way to do this on the front-end? Using Umbraco Version 4.6.1.

Furthermore, In the Administration of Umbraco, these are Users, not Members! So, I need to know if a User is logged into Umbraco, not Member(s)!


Solution

  • Nevermind, figured it out...

    private bool _IsAdminLoggedIn = false;
    
    if (umbraco.helper.GetCurrentUmbracoUser() != null)
    {
        _IsAdminLoggedIn = !string.IsNullOrEmpty(umbraco.helper.GetCurrentUmbracoUser().UserType.Alias) && umbraco.helper.GetCurrentUmbracoUser().UserType.Alias == "admin";
    }
    

    Now _IsAdminLoggedIn returns true or false depending if the UserType "admin" is logged into Umbraco or not!

    Cheers :)