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. Follow

3 Replies
1285 Views

Similar Articles

[PageSpeed] 57
Get it on Google Play
Get it on Apple App Store

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: 

Public MethodsPublic 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:

Similar Artilces:

How can i get the user id of the user currently logged in?
Hi, I need to get the userId of the user currently logged in. Do I need to use 'user profile' for that? I am using the database schemas installed by the aspnet_regsql.exe. Any suggestions will be very much appreciated. E     Dim user As MembershipUser        user = Membership.GetUser(True)        Label1.Text = user.UserName If this post was useful to you, please mark it as answer. Thank you!Regards.mimranshafiq.NET Web Developerhttp://www.dotnetclassic.com VB:Dim usr as MembershipUser=Membership....

get User ID from current user
hi, i'm trying to log database activity. therefore i need the user-id of the currently logged-in user. For the login i used the login-controls that come with VWD and set up a MS SQL Server 2000 Database for data storage. That part works fine, but i've found no way to get the id.i'd be glad for some hints.Thx, SönkeP.S.: found things linke user.identity.name and membershipuser.providerkey (or sth) - but this didn't help me. Are you aware of where the users are stored in the database?  Did you configure the personalization providers from the default?  If not, open up ASPNETDB.MDF a...

Getting the user name of the currently logged in user
I'm writing my first custom module. Just as an experimental project I would just display information about the currently logged in user. I can get the User Id, but I don't know where to get the rest of the information. How do I get this? Hi, Just create a new UserController to get the information about one user via the method GetUser(PortalId, UserId) and store it into a UserInfo. Then you can get the rest of the information from this UserInfo [VB] Dim myUser As New UserInfo Dim myUserController As New UserController myUser = myUserController.GetUser(PortalId, Use...

Getting currently logged in users ID
I have a table which stores user information in a different database aside from the ASPDB.Net one. This is so I can better manage the database and such. Now, I want to be able to use the UserID to link tables and so when i insert details into the database I want to be able to include the currently logged on users ID. I have tried to do a query which returns the users id and stores it on a profile parameter i added called profile.userid. But this doesnt seem to work. Any ideas on how i could better fetch the primarykey?   To get the ID of the current user logged in use t...

Web page not detecting a logged in user/user not logging in
Hey guysAs it stands, I've created two web pages within my app. One is a login page which is simply a blank page with the login control dragged on top. Within this control I redirect to my second page which contains a set of asp:Panels that are supposed to hide/display depending on which user is browsing the page.I've read several tutorials and at the moment, I've installed memberships/roles using the aspnet_regsql application. I've also used the web administration tool to create an 'administrators' role and create a user which is assigned to that role. I've also ...

Session problem(Previous Users log-in details are getting displayed/withheld for the current user)
Hi we've hosted Bugzilla in windows 2000 server & it has been used by many users at a given time.we've been getting this peculiar Session problem.ie.If a user logs-in, the page that he visits contains the details of another user who has just signed out from bugzilla.Any & all suggestions are welcome. Regards Tamil ...

How to Get the Currently Logged in Computer User within the Web Page
I'm creating an ASP.Net web application and the requirement is that users on our intranet ( AD-LDAP authenticated ) have the option, when first browsing to the logon page, to either be logged on through their current user account automatically, or be given a chance to log on as a different user. So the Logon page needs to be able to determine who is currently logged on to the computer. How can I do this? I have the LDAP forms-based authentication working already. Thanks Very Much in Advance.  David      Page.User.Identity.Name Curt_C: Page....

User object (System.Security.Principal.IPrincipal) in my web service does not reflect currently logged on user.
I am using Forms authentication, 3.5 framework. I am calling a web method from a web form page; here is my problem: For some reason the User object (System.Security.Principal.IPrincipal) in my web service does not reflect currently logged on user. I know I am logged in correctly when I call the web service method (which I call using BeginX...X()). The weird thing is, I have other services whos methods DO reflect the currently logged in user (although these are called using AutoComplete extender, don't know why one works and the other does not).Please help  http://www.geneangelo...

how to get user data from a logged in user
I have the standard login controls from ASP.NET 2.0 on my site. Now i've added a id field from another table to the aspnet_users table as FK. Now i want to use this ID (if the user is logged in) to populate my datagrid. How can i get this ID?  Erik    Check below link Work With Membership API HCHaissam Abdul MalakMCAD.NET| Blog | Hi Please follow the link http://forums.asp.net/thread/1702250.aspx and raise the problem you've meet :) Good luckBest RegardsXiaoYong DaiMicrosoft Online Community SupportPlease remember to click “Mark as Answer” on the ...

get user name by user id
hi i send the user ID to a page and there i wanna find the user name. can you please let me know how to find a user name by user id? tanks  Are you using Active Directory? If so check out this tutorialCommunity Coder Hi you can pass the Guid USerId to Membership.GetUser method,MembershipUser usr = Membership.GetUser(UserIDAsGuid); string userName = usr.UserName; // to get the current logged in username , just use HttpContext.Current.User.Identity.Name;    Regards,Anas Ghanem.Note:Please Don't hesitate to click "Report Abuse" link if you noticed som...

Current User Logs out after creating new user.
Hi,  I am using the asp.net membership provider for managing users in my application. I have created the required database in SQL server 2005. I am using the standard membership controls provided. (Login control, CreateUserWizard control etc.) . As per business logic of my application, the user do not create their account themselves. The Admin user creates them instead. For user creation, I have created a page with the CreateUserWizard control. I have made necessary membership settings entries for the web.config file. So, the user gets created without any line of code. But...

How to List out Current Log on Users
Dear All,              I want the efficent way to display Current Log on Users - Users in online.  If u store session of all user in database then u can easily get the online user by checking the session state stored in database.  Add the Login info in the database . Check this info regularly after some time interval and show on the page Thanks & Regards Sandeep If you want something you never had, do something you have never done! Try storing the online persons count in the Application State Aminhttp://3...

creating a new user logs out the current user
Hi everybody, I am developing a web application, currently I am working on the security aspect of the web app. The problem I am having is when I create a new account (when I sign in as an admin user) using CreatNewUser Wizard, a new user is created and it automatically logs out the current user(Admin) and get itself  logged in. Could anybody help me out here. Thanking you in anticipation. Regards. There is a property on the <asp:createuserwizard> control called "LoginCreatedUser" (this is a Boolean) that allows you to control whether a newly created user is au...

Users logging in as the same user..
HI there.. I have a problem with ASE12.0 .. I have created 10 users on the database and granted everybody permissions and all.. However, it seems everybody, no matter who logs in, logs in as the same user.. For eg... I have user logins John, Alex, Alan, Steve......etc etc And i created a user group for all of them (eg developers..) However, when they log on to isql, anything that they do will be under John, no matter if it is logins John, Alex, Steve... or etc etc.. If i do a sp_who.. all the connections will be listed as John. If they create tables, all table created will ...

Web resources about - how to get the user id of the currently logged in user? - asp.net.web-forms

Video Distribution Startup VHX Is Now Building Apps For Phones, Tablets And Internet-Connected TVs
VHX, a startup that helps customers sell videos online, is taking a big leap into mobile, with new capabilities for publishers to launch their ...

North Korea claims to have tested "Hydrogen bomb of Justice"
Angry mad uncle kingdom North Korea claims to have detonated a hydrogen bomb , but observers are skeptical because the new blast was no beefier ...

Samuel L. Jackson Didn't Know He Had 'Beef' with Donald Trump, Fires Back at His Comments
Samuel L. Jackson makes an appearance on Late Night with Seth Meyers to discuss his supposed “beef” with Donald Trump on Tuesday (January 5) ...

Wall Street thinks Twitter's 10,000 character plan is 'desperate' and so do you
Good news, Twitter: you've finally accomplished the impossible, getting Wall Street and your user base to agree about something. Bad news: they ...

Asylum applications to the UK more than double in ten months to 5,095 – the highest figure for 6 years ...
Asylum applications to the UK more than double in ten months to 5,095 – the highest figure for 6 years – but are still below other EU countries ...

'Making a Murderer' rape victim speaks: 'I absolutely wanted the earth to swallow me'
Over the course of its 10-hour run time, Netflix's Making a Murderer introduces viewers to all sorts of colorful characters involved in the saga ...

Iraq offers to mediate between Saudi Arabia, Iran
TEHRAN, Iran (AP) — Iraq on Wednesday offered to mediate between Saudi Arabia and Iran after tensions soared following the kingdom's execution ...

Opinion: Apple cuts iPhone manufacturing?
Roll up, roll up for the amazing post-Christmas Apple -FUD-frenzy as weird tales claiming it has cut iPhone production spread. Buy on rumor ...

It looks like Google gave $6 million in free advertising to the Church of Scientology
In 2014, Google gave about $6 million in free advertising to the Church of Scientology, an activist for the church has claimed. Few people noticed ...

The Latest: New El Nino storm moves into California
seattlepi.com The Latest: New El Nino storm moves into California seattlepi.com Authorities investigate a multi-vehicle crash involving a ...

Resources last updated: 1/6/2016 3:44:52 PM