Friday, March 23, 2012

Replace LoginName control with other data fields from aspnetdb.mdf

I currently have a LoginStatus and LoginName control on my asp.net 2.0 master page. When successfully logged in a message displays "You are logged in as" LoginName. Since I am using the user's e-mail address as the UserName the message will display as "You are logged in as johndoe@.foo.com".

What I want to do is have the message display as "You are logged in as " FirstName LastName. FirstName and LastName are two new fields that I added to the table, aspnet_Users.

What I have done is to use the FormView control to display FirstName and LastName; however this always displays the first record in the aspnetdb database.

Is there a cleaner way (than the FormView control) to display the requested data, using the currently logged in user? I have access to Microsoft Expression Web and Visual Studio 2005, but I prefer Expression Web.

Thank you in advance

Hi,

From your description, it seems that you want to get the FirstName and LastName field for the logon user, right?

If so, I think you can get the current user's name by using User.Identity.Name, and then, invoke the GetUser method of Membership with the current user's name, which can return a MembershipUser typed object. You can access the data filed in the membership tables.

Thanks.

No comments:

Post a Comment