Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Rotem Orbach 104 posts 577 karma points
    Sep 02, 2020 @ 13:32
    Rotem Orbach
    0

    Umbraco 8.2.2 - Get current user (not member) in front side website view/cshtml

    Hello,

    I am trying to either get the current Umbarco user (not member) in the front side of the website (inside a 'cshtm' view), or simply find if there is a User logged in.

    I understand that around V.8 using services is the way to go, so I tried based on

    IUserService userService = Services.UserService;
    

    But I can't find a working way to find a user.

    I tried a deep Google search and during many hours tried many other ways (some outdated or deprecated by now).

    Surely there has to be a way...

    Any help would be appreciated :)

    Many thanks,

    Rotem

  • Rotem Orbach 104 posts 577 karma points
    Sep 02, 2020 @ 13:54
    Rotem Orbach
    100

    I spent hours on this... for others and for future reference, here is the answer:

    1. Make sure you use:

      @using Umbraco.Web.Security

    2. bool isLoggedin = new HttpContextWrapper(HttpContext.Current).GetUmbracoAuthTicket() != null;

  • Steve Morgan 1208 posts 3922 karma points c-trib
    Sep 02, 2020 @ 14:04
    Steve Morgan
    0

    Hi,

    I've not had to do this myself but this seems to work.

    I've no idea if it's the "proper" way.

    @using Umbraco.Web.Security
    @{
        Layout = "Master.cshtml";
    
        var auth = new HttpContextWrapper(HttpContext.Current).GetUmbracoAuthTicket();
    
    
    }
    

    Via RJ on https://our.umbraco.com/forum/umbraco-8/96524-show-content-for-backend-admin-only

    EDIT: Cross posted with Rotem - he was first ;)

Please Sign in or register to post replies

Write your reply to:

Draft