简体   繁体   中英

User exists in aspnet_membership table but getUser still returns null

In my database I have the table aspnet_membership. In the application I am implementing the forgot password functionality. When the user is using this functionality he obviously isn't logged in. So the user enters his e-mail address of which he can't remember the password and in my code I try to get the correct MembershipUser object by executing this line of code:

var user = Membership.GetUser(username);

While testing, I enter and existing e-mail address but the function GetUser still returns null. I am sure the e-mail address exists by checking the content of the table. I cannot figure out what the reason is why I still get the null value returned. Can anyone tell me why GetUser returns null in this scenario?

Because the username isn't actually stored in the aspnet_membership table (assuming default implementation) - username is in aspnet_users .

I would try doing the following and seeing if you get a result:

declare @email nvarchar(50)
set @email = N'whateveremailyouarehavingproblemswith'

select * 
from aspnet_membership m 
inner join aspnet_users u on m.userId = u.userId 
where m.email = @email 
    and u.username = @email

if nothing is returned from this query, then either your usernames and emails aren't matching, or that user does indeed not exist.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM