confusion over the 'MemberService' and 'UserService' and getting the current umbraco user
hey out there,
i've found lots of pointers online but no concrete solution to what i'm trying to achieve. i'm also getting a lot of 'obsolete' warnings with code i'm finding online...
i have a form in my website that i want to show an additional checkbox if an admin user is logged into the umbraco back office. i don't have any membership stuff set up on this site.
so, which service do i use?! i've tried both and can't seem to get the currently logged in umbraco user using either!
based on what i'm finding, it should be something like:
var memberService = ApplicationContext.Current.Services.MemberService;
var member = memberService.GetByUsername(HttpContext.Current.User.Identity.Name);
var userService = ApplicationContext.Current.Services.UserService;
var user = userService.GetByUsername(HttpContext.Current.User.Identity.Name);
Where have you found the userService? I have not been able to find anything about it in the documentation section.
However - In Umbraco terms Users are people who can access the Umbraco backoffice and Members are people who can access a login restricted area on the public website.
i went through pretty much the same steps as outlined in the post, i.e. visual studio telling me 'umbraco.BusinessLogic.User.GetCurrent()' was obsolete and i should 'Use the UserService instead'.
the main problem i'm having is that 'HttpContext.Current.User.Identity.Name' (which i thought uses the asp.net membership stuff to get the guid of the currently logged in user) is always returning empty, regardless of if i'm logged into umbraco or not...
which says to me that i need to get the currently logged in umbraco user in a different way - the question is how ;)
public IUser GetCurrentUser()
{
var auth = new HttpContextWrapper(HttpContext.Current).GetUmbracoAuthTicket();
if (auth == null) return null;
var user = ApplicationContext.Current.Services.UserService.GetByUsername(auth.Name);
return user;
}
confusion over the 'MemberService' and 'UserService' and getting the current umbraco user
hey out there,
i've found lots of pointers online but no concrete solution to what i'm trying to achieve. i'm also getting a lot of 'obsolete' warnings with code i'm finding online...
i have a form in my website that i want to show an additional checkbox if an admin user is logged into the umbraco back office. i don't have any membership stuff set up on this site.
so, which service do i use?! i've tried both and can't seem to get the currently logged in umbraco user using either!
based on what i'm finding, it should be something like:
but neither of these return me a user!
can someone provide a any clarity?!
cheers,
jake
Hi Jake
Where have you found the userService? I have not been able to find anything about it in the documentation section.
However - In Umbraco terms Users are people who can access the Umbraco backoffice and Members are people who can access a login restricted area on the public website.
/Jan
hey jan,
thanks for clarifying that - i hadda feelin that would be the case as in 'users' are umbraco back office and 'members' are website users.
the main pointers i've found for the user service from another forum post:
https://our.umbraco.org/forum/developers/api-questions/50075-how-to-get-the-current-user-with-UserService
i went through pretty much the same steps as outlined in the post, i.e. visual studio telling me 'umbraco.BusinessLogic.User.GetCurrent()' was obsolete and i should 'Use the UserService instead'.
the main problem i'm having is that 'HttpContext.Current.User.Identity.Name' (which i thought uses the asp.net membership stuff to get the guid of the currently logged in user) is always returning empty, regardless of if i'm logged into umbraco or not...
which says to me that i need to get the currently logged in umbraco user in a different way - the question is how ;)
the search continues...
cheers,
jake
got it! bit more googling and came up with:
works a treat ;)
is working on a reply...