Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I'm using the Umbraco MemberShipHelper. The helper has 2 methods:
The first method returns an IPublishedContent. How can I get the email of a member from that? The property is available on the ProfileModel that GetCurrentMemberProfileModel() returns, but I prefer not to use 2 methods to get the current member.
I had to write some code to do this a few versions back (v7.2) and then you couldn't get it from the IPublishedContent model.
there is an issue somewhere so i am not sure if it got fixed in later versions - but i ended up making the member dynamic
var email member.AsDynamic().Email;
bit of a hack but it works.
I've used the membership helper in this way and can return any of the properties
var memberShipHelper = new Umbraco.Web.Security.MembershipHelper(Umbraco.Web.UmbracoContext.Current);
var myUser = memberShipHelper.GetCurrentMember();
I'm using a 7.2.x and I've had no problems with it
Thanks for the tips. Will try myUser.GetProperty("Email").Value. The reason I didn't try it is because email isn't a property set on the member type. When the models builder generated a strongly typed model it also didn't contain an email property.
When you reference a member by IPublishedContent it is really an instance of MemberPublishedContent. If you cast to this type, you will have acces to an email property (as well as other member-only properties):
IPublishedContent content = Umbraco.TypedMember(memberId);
MemberPublishedContent member = (MemberPublishedContent) content;
When I try to do this I get this error (using umbraco 7.7.2):
Unable to cast object of type 'Umbraco.Web.PublishedContentModels.Member' to type 'Umbraco.Web.PublishedCache.MemberPublishedContent'.
Getting the same error if I try to use ApplicationContext.Current.Services.MemberService.GetById(memberId)
Since I'm using the ModelsBuilder I don't get a MemberPublishedContent back, but the generated model which doesn't have the Email property. I fixed it with this code:
public partial class Member
public string Email
Sorry for the newb question and more than a year later :)
But where would I put this? (Not in the auto-generated file I'm guessing)
You can put this in it's own file in somewhere such as the App_Code folder (you might need to create this).
the generated classes are marked as partial, which means you can create other partial classes with the same name across your project and they are turned into one class as compile/run time.
Thanks Jeroen. This was the exact same situation i found myself in. Your reply just saved me a little time. Thank you.
I have found you can get the email dynamically, but not typed:
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted