What is this?

This post shows you how to get the current logged in Umbraco user and restrict content on the front end of the site.

Ok, show me how

@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@using Umbraco.Core @using Umbraco.Core.Security @using Umbraco.Core.Models.Membership
@{     Layout = null;
    bool isLoggedInUser = false;     IUser currentUser = null;
    var userTicket = new System.Web.HttpContextWrapper(System.Web.HttpContext.Current).GetUmbracoAuthTicket();
    if (userTicket != null)     {         isLoggedInUser = true;         currentUser = ApplicationContext.Services.UserService.GetByUsername(userTicket.Name);     } }
@if(isLoggedInUser) {     <p>Logged in as @currentUser.Name</p> } else {     <p>You must be logged in to umbraco to view this page</p> }

Basically, if it can get the user authentication ticket, it considers you logged in.

Then it just sets the bool value to say you are logged in and gets the user, using the user service, so you can access the properties of the user, if you want.

If you found this useful, please share it with others and bookmark it for later use.

Want to thank me?

If I've helped you out and you want to thank me, why not buy me a coffee?

About the author

Paul Seal

Umbraco MVP and .NET Web Developer from Derby (UK) who specialises in building Content Management System (CMS) websites using MVC with Umbraco as a framework. Paul is passionate about web development and programming as a whole. Apart from when he's with his wife and son, if he's not writing code, he's thinking about it or listening to a podcast about it.

Related Posts

How to ignore a file locally in git without ignoring it from the repository

This post shows you how you can ignore a file in git locally without ignoring it from the repository…

Read Post

How to get the picked item name in Stacked Content and Nested Content using ncNodeName

This post shows you how you can get the name of the picked item in Nested Content or Stacked Content…

Read Post

How I use source control for my Umbraco website source code and media

In this post I share my approach to using source control for my Umbraco website source code and medi…

Read Post

How to solve the error "Could not load file or assembly 'Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0 ..."

This post will show you how to solve the error "Could not load file or assembly 'Microsoft.CodeDom.P…

Read Post