how to get the user id of the currently logged in user?


hi,
      m develoing a site whereby employees are supposed to log in and take orders.  the users are being created thru the ASP web Administration tool and stored by default into the SQL Server Database named AspNetDB.mdf that's stored in the App_Data folder of our website. the database is created auomatically. How to display the userid as this userid is too complicated and there can be many users with the same username.
0
mandeep123
11/13/2007 4:51:02 AM
📁 asp.net.web-forms
📃 93655 articles.
⭐ 6 followers.

💬 3 Replies
👁️‍🗨️ 1285 Views



You can use the Membership class to get the info about a user:
Membership.GetUser()
The GetUser method can also take a username as argument if you need to get a specific user, if you don't pass a username, the current logged in user will be returned. The GetUser method returns a MembershopUser class which have a UserName property and a ProdiverUserKey which will return the id of the user.

/Fredrik Normén - fredrikn @ twitter

Microsoft MVP, MCSD, MCAD, MCT

ASPInsiders
My Blog
0
Fredrik
11/13/2007 5:29:09 AM

hi,
m grateful that u replied. but sorry, m not clear wit wat u said. Actually, m very new to asp.net. wat m trying is to display the username with the unique id and store the order details for that username and again retrieve it later from the DB. And also filter the orders based on this username but not on the userid as this userid's are stored in a complex format. i want to display and store the username along wit the id at the click of a button which will also store the order details into the DB. plz help me out wit the details of implementing this solution. thanx!
0
mandeep123
11/13/2007 6:20:38 AM

Hi mandeep123,
Please see the methods, they are under the MemberShip: 
<img src="http://forums.asp.net/msdn/Controls/CollapsibleArea/en-us/minus.gif" class="CollapseRegionImg" id="ctl00_LibFrame_ctl22img" alt="Public Methods" align="middle">Public Methods
(see also Protected Methods )
  Name Description
Public method Static CreateUser Overloaded. Adds a new user to the data store.
Public method Static DeleteUser Overloaded. Deletes a user from the database.
Public method Equals  Overloaded. Determines whether two Object instances are equal. (inherited from Object)
Public method Static FindUsersByEmail Overloaded. Gets a collection of membership users where the e-mail address contains the specified e-mail address to match.
Public method Static FindUsersByName Overloaded. Gets a collection of membership users where the user name contains the specified user name to match.
Public method Static GeneratePassword Generates a random password of the specified length.
Public method Static GetAllUsers Overloaded. Gets a collection of the users in the database.
Public method GetHashCode  Serves as a hash function for a particular type. (inherited from Object)
Public method Static GetNumberOfUsersOnline Gets the number of users currently accessing an application.
Public method GetType  Gets the Type of the current instance. (inherited from Object)
Public method Static GetUser Overloaded. Gets the information for a membership user from the data source.
Public method Static GetUserNameByEmail Gets a user name where the e-mail address for the user matches the specified e-mail address.
Public method Static ReferenceEquals  Determines whether the specified Object instances are the same instance. (inherited from Object)
Public method ToString  Returns a String that represents the current Object. (inherited from Object)
Public method Static UpdateUser Updates the database with the information for the specified user.
Public method Static ValidateUser Verifies that the supplied user name and password are valid.

 
and here is the link: http://msdn2.microsoft.com/en-us/library/system.web.security.membership_members.aspx
 
Please correct me if I have misunderstood your mean, please LET ME KNOW, Thanks, 
Hope it helps,
Hong Gang
 

Hong-Gang Chen
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Hong
11/15/2007 6:48:14 AM
Reply: