Copied to clipboard

Flag this post as spam?

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


  • Mike 10 posts 73 karma points
    Mar 27, 2015 @ 22:27
    Mike
    0

    Umbraco 7 Admin User Check

    I'm migrating over a IHttpModule from v4 to v7 that secures all .axd requests and makes sure you are logged into the umbraco backend before you can proceed.

    In v4 I used the umbraco.businesslogic assembly to call User.GetCurrent() but now in v7 this is always returning Null even though I'm logged into the umbraco admin section.

    In v7 how do I check if the current request is an admin user?

  • Alex Skrypnyk 6133 posts 23952 karma points MVP 7x admin c-trib
    Mar 28, 2015 @ 15:01
    Alex Skrypnyk
    0

    Hi Mike,

    You can use method like that:

    private int GetCurrentUserId()
    {
        var userService = ApplicationContext.Current.Services.UserService;
        return userService.GetByUsername(HttpContext.Current.User.Identity.Name).Id;
    }
    

    Also:

    UmbracoContext.Current.Security.CurrentUser
    

    For creating userService instance :

    using Umbraco.Core.Services;
    using Umbraco.Core.Persistence;
    var userService = new UserService(new RepositoryFactory());
    

    Thanks, Alex

  • Mike 10 posts 73 karma points
    May 19, 2015 @ 20:29
    Mike
    0

    Hey Alex,

    Is this getting the backoffice user or the membership user? When loged into the backoffice panel UmbracoContext.Current.Security.CurrentUser  returns null

Please Sign in or register to post replies

Write your reply to:

Draft