Umbraco Get Current Member or Member By ID

It seems like most pages when you Google for getting the current member or a member by id in Umbraco seem to be from back in 2010 or 2012, well things have changed since the businesslogic days and we're now in the world of Umbraco Services, how do we use them? Well, it's simpler than you think.

It used to be that you'd have to use the built in security methods such as Membership.GetUser(), or umbraco.cms.businesslogic.member.Member.GetCurrentMember(), but the former doesn't provide an Umbraco model and the latter, is horribly long, not very memorable and is also Obsolete!

Introducing the Membership Service:

You can access the membership service pretty easily by calling Services.Membership service and letting intellisense do the rest of the work for you by letting you know what else it offers, a quick example for getting e member by his/her username would be:

Services.MemberService.GetByUsername("username")

But that only works within a view/controller because they have an Umbraco context built in. For when you're not in a view or controller and you still need to access the services, it's a simple call to get the application context and suddenly they're all available to you:

ApplicationContext.Current.Services.MemberService.GetByUsername("username")

A great example for why you might use the above is for you're writing a helper method/class that makes use of the membership service but you don't want to take it as a parameter.

Getting the current member:

To get the current member, you'll need to use a mixture of the membership service and the .NET Membership provider, but it's simple enough, just call it like so:

ApplicationContext.Current.Services.MemberService.GetByUsername(Membership.GetUser().UserName);

Tadahh!

P.S: Just for the sake of a complete article, ApplicationContext is located in Umbraco.Core, so go ahead and add a using statement for that before calling it. Also Membership is located in System.Web.Security.


Published at

Tags: Umbraco,C#,MVC

Luke Alderton

Comments

Lee Messenger
Just remember you are hitting the database with the call from the MemberService (Unless things have changed). You should (Again unless things have changed) still be able to use MembershipHelper to get a cached IPublishedContent version of the member. See this post I wrote a while back. https://24days.in/umbraco-cms/2014/dealing-with-members/
04/09/2018
Owamo73
https://n-i-n-a01.tumblr.com https://le-petit-yeol.tumblr.com https://nao-acorde.tumblr.com https://ezquadros.tumblr.com https://strangekoi.tumblr.com https://devon-m83.tumblr.com https://derhan35.tumblr.com https://ronnierockin.tumblr.com https://letters-and-fire.tumblr.com https://dylenalover.tumblr.com https://binaevymii.tumblr.com
01/12/2018
Iduke49
https://thickgoku.tumblr.com https://moonligh---t.tumblr.com https://mayasizviski.tumblr.com https://jay-nicay8d.tumblr.com https://fuckthemajortomyeah.tumblr.com https://curvesgalorexx.tumblr.com https://mythoughtsbl0g.tumblr.com https://mingau-de-chocolate.tumblr.com https://urbanparadise.tumblr.com https://frases-status-amor.tumblr.com https://showbadgirl.tumblr.com https://l7300.tumblr.com https://blarsonx.tumblr.com https://ic69.tumblr.com https://mylittlegirlsuicide.tumblr.com https://01-maddy-12.tumblr.com https://agravio-moral.tumblr.com https://oxyt0cln.tumblr.com
02/12/2018
FloydAppal
http://mysite.ru - http://mysite.ru
06/12/2018
Petas22
http://shamrockballerz.ning.com/profiles/blogs/como-fa-o-para-comprar-prilo-sildenafil-citrate-sem-prescri-o http://www.1friend.com/blogs/2618/14236/buy-mestinon-60mg-where-can-i-buy-pyridostigmine-bromide-chea http://network-marketing.ning.com/profiles/blogs/site-seguro-para-comprar-escitan-sildenafil-citrate-gen-rico-sem http://whazzup-u.com/profiles/blogs/como-comprar-virineo-sildenafil-citrate-200mg-gen-rico-sem http://www.1friend.com/blogs/2621/14505/site-serieux-acheter-longis-tadalafil-60mg-pharmacie-en-ligne http://kasabovart.ning.com/profiles/blogs/buy-permite-30mg-safely-where-to-order-permethrin-no-prescription http://property.ning.com/profiles/blogs/farmacia-online-donde-comprar-elonza-sildenafil-citrate-sin http://www.onfeetnation.com/profiles/blogs/androz-50mg-order-without-rx-androz-where-safe-to-buy-no http://fotoathena.ning.com/profiles/blogs/para-comprar-generico-gemfibrozilo-con-garantia http://thehiphophub.ning.com/profiles/blogs/onde-comprar-ah-zul-envio-urgente-pela-net-brasil http://cdloga78.ning.com/profiles/blogs/speedgra-sildenafil-citrate-120-mg-livraison-express-bon-prix http://conniesdance.ning.com/profiles/blogs/zyad-tadalafil-en-ligne-acheter-livraison-24h-rx-pharmacy-acheter
08/12/2018
Andrewjek
Привет всем я очень люблю смотреть фильмы онлайн и хочу представить вашему вниманию сайт http://filminov.ru/ В любое время вы сможете увидеть Лучшие фильмы фэнтези онлайн 2016-2017 новинки http://filminov.ru/films/fentezy/ - фэнтези смотреть онлайн 2016-2017 новинки Лучшее историческое кино 2015 2016 2017 новые новинки http://filminov.ru/films/istoria/ - http://filminov.ru/films/istoria/ Смотреть лучшие криминальные фильмы онлайн http://filminov.ru/films/kriminal/ - Смотреть лучшие криминальные фильмы онлайн Лучшие мультфильмы 2016 2017 cмотреть онлайн бесплатно http://filminov.ru/films/multik/ - Лучшие мультики бесплатно в хорошем качестве смотреть онлайн hd 720p Лучшие приключенческие фильмы смотреть онлайн http://filminov.ru/films/prikluch/ - http://filminov.ru/films/prikluch/ Лучшие спортивные фильмы бесплатно в хорошем качестве http://filminov.ru/films/sports/ - http://filminov.ru/films/sports/ лучшие и новые ужасы бесплатно в хорошем качестве hd http://filminov.ru/films/ujas/ - http://filminov.ru/films/ujas/ Прошу обратить внимание: http://filminov.ru/films/multik/37503-smotret-kosmicheskiy-pirat-harlok-onlayn.html - http://filminov.ru/films/multik/37503-smotret-kosmicheskiy-pirat-harlok-onlayn.html
10/12/2018
Post a comment
Sit tight...
We're adding your comment.
Thank you.
Your comment has been added.
There's been a problem.
Please try again later.
Share with
Tags
Latest Comments
By Ecake68 on MVC forms in Umbraco
16 Dec 2018, 16:11 PM
By Wowob43 on Restrict Umbraco Back Office by IP
16 Dec 2018, 10:21 AM
By Rosax69 on How does DNS work? For dummies!
15 Dec 2018, 16:44 PM
By Aroli61 on Using SQL DataTables to speed up database performance
15 Dec 2018, 09:02 AM
By Xasus39 on MVC forms in Umbraco
14 Dec 2018, 20:04 PM
By Shane on Xamarin Forms multiple instances of same app open
14 Dec 2018, 05:33 AM
By Apabu19 on Displaying text on a 16x2 LCD screen with a Raspberry Pi
13 Dec 2018, 18:26 PM
By Anuri66 on Using SQL DataTables to speed up database performance
13 Dec 2018, 13:52 PM
Categories
App Development
Event
Game Development
Mapping
Modelling
Programming
Review
Robotics
Tutorial
Web Development