D.J
D.J

Reputation: 2534

asp.net membership provider get UserName by UserId

I have seen a lot of question asking about known user name and how to retrieve UserId accordingly. How about the other way around?

For some reason I have UserId, but I don't want to include aspnet_User table into my data entities. Is there any way I can retrieve the user name without querying against aspnet_User table?

Upvotes: 4

Views: 7877

Answers (1)

Jonathan Wood
Jonathan Wood

Reputation: 67175

MembershipUser user = Membership.GetUser();
if (user != null)
    string name = user.UserName;

Internally, this will access the ASP.NET user table. There's no way to avoid that.

Upvotes: 2

Related Questions