Copied to clipboard

Flag this post as spam?

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


  • Dan 1288 posts 3921 karma points c-trib
    Jul 01, 2014 @ 00:35
    Dan
    0

    Check if back-office user is logged in using UserService

    Hi,

    I'm trying to check whether a back-office user is logged in to a front-end web page. Ordinarily I'd do something like this to get the current user:

    var currentUser = umbraco.BusinessLogic.User.GetCurrent();
    

    However, Visual Studio is telling me "'Umbraco.BusinessLogic.User' is obsolete. 'Use the UserService instead'".

    How do I do get the current user with the new UserService?

    Thanks.

  • Morten Christensen 596 posts 2773 karma points admin hq c-trib
    Jul 01, 2014 @ 15:04
    Morten Christensen
    101

    Try using the UmbracoContext like this:

    var user = UmbracoContext.Current.Security.CurrentUser();
    

    If you are using an UmbracoApiController you will already have the WebSecurity instance available, so you can just do:

    var user = this.Security.CurrentUser();
    

    Hope this helps.

  • Dan 1288 posts 3921 karma points c-trib
    Jul 01, 2014 @ 15:11
    Dan
    0

    Great, thanks Morten.  Where's the best place for me to find stuff like this out?  I know the documentation isn't ready yet for the User Service, but I'm struggling, as a predominantly front-ender, to get my head around the Umbraco source to uncover stuff like this.  I'm getting confused by what's legacy and what's new, when to use the Service APIs and when to use .NET membership stuff, and what the code-base differences are between members and users as there seems to be some kind of overlap - it's all a bit of a pickle in my head currently.  If you could point me in the right direction either in the source or somewhere else it'd be mega handy.  Thanks again :)

Please Sign in or register to post replies

Write your reply to:

Draft