Search code examples
c#model-view-controllerconditional-statementsumbracoroles

Conditional check if user is logged in Umbraco


How can i check if user is logged in to umbraco from the view(.cshtml)?

I would also know how to check the users role.

User.Identity.IsAuthenticated always returns false.

if( User has role = "someRole" )  
{  
    do stuff
}

Im using Umbraco version: 7.8.1


Solution

  • I found this code to be working for my application:

    var auth = new HttpContextWrapper(HttpContext.Current).GetUmbracoAuthTicket();  
    
    if (auth != null)
      { <p>Name: @auth.Name</p>
        <p>ID: @auth.UserData</p>
      }
    

    Resource : "Umbraco.Web.UmbracoContext.Current.Security.CurrentUser" returns "null" for front-end requests