views:

1107

answers:

4

Hello, I use a membership in asp.net 2008. And I build a login system with some rolls ...etc

I have a database and tables and the KEY is "username", and now I want to know how can I get a username for the member who logged in ?

for example: I logged in as TURKI I want to get the username TURKI

really I need for help...

thanks,

+6  A: 
User.Identity.Name

User is a property of the page. If you need to access it elsewhere, you can use:

HttpContext.Current.User.Identity.Name
eglasius
Thanks, I try User.Identity.Nameand it's OK!really thanks!
@Turki glad to help :) as it worked for you, mark the answer as accepted :)
eglasius
Both of the above work fine in a intranet environment when browsing to the page from my local PC - BUT - neither seems to work when logged into our Windows 2003 Terminal Server.
John M
@John what do u mean with an intranet environment? as u are talking about a difference in behavior, I will take a guess and assume u are not talking about using the sql membership provider, but instead are using integrated authentication. In that case first thing I would check is if that server allows anonymous user. If not, pls post more details, if its long u might want to post a separate question - drop me a link here in that case (although is prob that someone else will answer it before I check again ...)
eglasius
A: 

Context.User.Identity.Name

Al Katawazi
thank yougood answer
A: 

you can use the Membership.GetUser() method described here:

http://msdn.microsoft.com/en-us/library/system.web.security.membership.getuser.aspx

also, if you do get the MembershipUser you could also get the 'ProviderUserKey' which uniquely identifies a user, possibly using that as your FK for your tables, that way your user can have their username updated without having to change all the keys in your tables.

John Boker
thank yougood answer
A: 

A modification to Freddy's answer when using MVC - had to use:

HttpContext.User.Identity.Name

Slight change but figured I would post it in case anyone else trying to do this in MVC hits the same snag.

Bob Palmer