if (Membership.ValidateUser(model.Username, model.Password))
{
FormsAuthentication.SetAuthCookie(model.Username, false);
TempData["LoginSuccess"] = true;
var log = Umbraco.MembershipHelper.Login(model.Username, model.Password);
var mem = Membership.GetUser();
}
Although variable log shows true in debugging, variable mem returns as null only. What am I missing here?
I'm not that familiar with Umbraco 7, but in 8 I generally do the following
if(Members.Login(model.siemail, model.sipassword)){
FormsAuthentication.SetAuthCookie(model.siemail, false);
var member = Members.GetByUsername(model.siemail);
}
I have only ever used GetUser() in a view not in a controller
But I need to get the current logged user not any user by his username. Hence used Membership.GetUser() . And for me in View also Membership.GetUser() is not working. Even Umbraco.MemberIsLoggedOn() is returning false for me in the view.
As I explained above In my case the issue is that the member is not getting logged in, So there is no point in getting a member by username. But I appreciate you trying to answer my question :)
I believe the problem is because you are checking getuser immediately after writing the Auth ticket and this will not work as it has not been loaded as it requires a web request for the browser to load the ticket which is why it works in my view. If after login you redirect to another page or reload the login page I think you should find that getuser works as expected.
I have changed my code according to your suggestion
if (Membership.ValidateUser(model.Username, model.Password))
{
FormsAuthentication.SetAuthCookie(model.Username, false);
return Redirect("/myprofile");
}
And tried to get the user in myprofile view. But still I am getting NULL for Membership.GetUser(). I have started thinking that I may be missing any important entry in webconfig or so. But I am not sure what all are the inportant entires in webconfig to make this member login work.
Umbraco member is not getting logged IN
My code to log in an Umbraco member is like this
Although variable log shows true in debugging, variable mem returns as null only. What am I missing here?
I'm not that familiar with Umbraco 7, but in 8 I generally do the following
I have only ever used GetUser() in a view not in a controller
I believe we both are using same code to get he user logged
But I need to get the current logged user not any user by his username. Hence used
Membership.GetUser()
. And for me in View alsoMembership.GetUser()
is not working. EvenUmbraco.MemberIsLoggedOn()
is returning false for me in the view.My code is getting the user you that just logged in, just because it is getting them by username doesn't mean it is a different member.
Like I said I have only ever used getuser() in a view and it works fine there, so maybe just doesn't work in a controller
As I explained above In my case the issue is that the member is not getting logged in, So there is no point in getting a member by username. But I appreciate you trying to answer my question :)
Are you able to check that the cookies are being written?
I believe the problem is because you are checking getuser immediately after writing the Auth ticket and this will not work as it has not been loaded as it requires a web request for the browser to load the ticket which is why it works in my view. If after login you redirect to another page or reload the login page I think you should find that getuser works as expected.
When login gets completed, I can see a new cookie named
.ASPXAUTH
I have changed my code according to your suggestion
And tried to get the user in
myprofile
view. But still I am gettingNULL
forMembership.GetUser()
. I have started thinking that I may be missing any important entry in webconfig or so. But I am not sure what all are the inportant entires in webconfig to make this member login work.do you have an ASP.Net _sessionId cookie as well ?
These are the two cookies I get when logging in as a member
This is how it looks for me
My issue was that I was missing below section in web.config
@reddick 's answer helped me to find this
Glad you finally sorted it.
is working on a reply...