Access Umbraco back office user from the front end

If you need to access the current user logged into the Umbraco Backoffice from the Front End (to show a link to administrator area for example) you may have tried:

umbraco.BusinessLogic.User.GetCurrent()
UmbracoContext.UmbracoUser
UmbracoContext.Security.CurrentUser
umbraco.helper.GetCurrentUmbracoUser()

None of which seem to work, then you should user the following code:

@using Umbraco.Core.Security;
var userTicket = new System.Web.HttpContextWrapper(System.Web.HttpContext.Current).GetUmbracoAuthTicket();
if (userTicket != null) {     
 var currentUser = ApplicationContext.Services.UserService.GetByUsername(userTicket.Name);
}

As Andrew Wilson mentions in the comments, remember to include Umbraco.Core.Security – though if you forget hopefully Visual Studio will tell you to add it.

7 thoughts on “Access Umbraco back office user from the front end

  1. Good solution, don’t forget to include:

    @using Umbraco.Core.Security;

  2. +1
    Thanks!
    Belongs in a hall of fame for useful Umbraco hacks. 😉

  3. Hey GR 😉

    Handy tip this. Cheers for posting

  4. Where does this code snippet go?

    • This code can go in either a razor view or a controller

      • When trying in razor I get the following error: ‘System.Web.HttpContextWrapper’ does not contain a definition for ‘GetUmbracoAuthTicket’ and no extension method ‘GetUmbracoAuthTicket’ accepting a first argument of type ‘System.Web.HttpContextWrapper’ could be found

Leave a Reply

Your email address will not be published. Required fields are marked *