I'm using the Umbraco MemberShipHelper. The helper has 2 methods:
GetCurrentMember()
GetCurrentMemberProfileModel()
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'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();
@myUser.GetProperty("Email").Value
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):
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
{
get
{
return this.GetPropertyValue<string>("Email");
}
}
}
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.
Get member email from IPublishedContent
Hello,
I'm using the Umbraco MemberShipHelper. The helper has 2 methods:
GetCurrentMember() GetCurrentMemberProfileModel()
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.
Jeroen
Hi,
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
bit of a hack but it works.
Jeroen,
I've used the membership helper in this way and can return any of the properties
@myUser.GetProperty("Email").Value
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.
Jeroen
Hi Jeroen,
When you reference a member by
IPublishedContent
it is really an instance ofMemberPublishedContent
. If you cast to this type, you will have acces to an email property (as well as other member-only properties):When I try to do this I get this error (using umbraco 7.7.2):
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:
Jeroen
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)
Hi
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...