Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I was wondering if it's possible to determine whether or not a viewer is logged into the backoffice or not without hitting the database.
For a long time I've been using the following code in the small amount of circumstances in which I've needed to know it:
var auth = new HttpContextWrapper(HttpContext.Current).GetUmbracoAuthTicket();
if (auth == null)
var backofficeUser = ApplicationContext.Current.Services.UserService.GetByUsername(auth.Name);
return backofficeUser != null;
However I now need to determine if a viewer is logged into the backoffice or not on all pages, meaning a method that does not hit the database (UserService initializes and uses a database repository) would be far more ideal.
I've attempted UmbracoContext.Current.Security.ValidateCurrentUser() however this returns false on the front-end (It depends on HttpContext.Current.GetCurrentIdentity(bool) which returns null on the front-end for some reason).
I wrote a blog post about it here. https://codeshare.co.uk/blog/how-to-get-the-current-logged-in-umbraco-user-and-restrict-front-end-content/
You can ignore the line about getting the actual user and just see if they are logged in like this.
var userTicket = new System.Web.HttpContextWrapper(System.Web.HttpContext.Current).GetUmbracoAuthTicket();
var isLoggedInUser = userTicket != null;
I spent hours going through the Umbraco code to try and find a solution and it was right there in front of me!
Thank you Paul, I don't know how I haven't died from drinking expired milk or something yet.
I hate it when that happens, but I'm glad you got it sorted.
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted