How can I get CURRENT USERNAME in membership asp.net 2008

后端 未结 4 488
盖世英雄少女心
盖世英雄少女心 2020-12-16 01:32

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 kno

相关标签:
4条回答
  • 2020-12-16 01:45

    Context.User.Identity.Name

    0 讨论(0)
  • 2020-12-16 01:46

    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.

    0 讨论(0)
  • 2020-12-16 01:55

    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.

    0 讨论(0)
  • 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
    
    0 讨论(0)
提交回复
热议问题