For some reason I am not able to get a logged in users id.. here is my code:
var membershipHelper = new Umbraco.Web.Security.MembershipHelper(Umbraco.Web.UmbracoContext.Current);
// attempt to sign in using umbracos login method
var signInSuccessful = membershipHelper.Login(user.Login, request.Password);
if (signInSuccessful)
{
int userId = umbraco.cms.businesslogic.member.Member.GetCurrentMember().Id;
}
i get a null reference exception on the userId = it thinks there is no member.
From what I can see everything should work, am i missing something in the config maybe?
I would really appreciate any help.
I have also tried: membershipHelper.GetCurrentMemberId();
Why dont you use the .GetByUsername(string username) ? since you've just logged him in ?
If it has to be done else where, you could use the membershipHelper.GetCurrentMemberProfileModel() and then fetch the id by looking up the user from the user name ?
Nope, membershipHelper.GetCurrentMemberProfileModel() returns null. It's not working at all. There must be some setting in the web.config that isn't right.
Need to get logged in members ID weird issue
For some reason I am not able to get a logged in users id.. here is my code:
i get a null reference exception on the userId = it thinks there is no member.
From what I can see everything should work, am i missing something in the config maybe?
I would really appreciate any help.
I have also tried: membershipHelper.GetCurrentMemberId();
But this returns -1 :/
Hello Trent
Why dont you use the .GetByUsername(string username) ? since you've just logged him in ?
If it has to be done else where, you could use the membershipHelper.GetCurrentMemberProfileModel() and then fetch the id by looking up the user from the user name ?
Hope this helps :)
Nope, membershipHelper.GetCurrentMemberProfileModel() returns null. It's not working at all. There must be some setting in the web.config that isn't right.
is working on a reply...