Wrox Programmer Forums
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old October 4th, 2006, 05:32 PM
Authorized User
Join Date: Jul 2006
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default Return UserId from aspnet_Users


I am tring to grab UserId from aspnet_users table in aspnet.db after user X loggen in and put it in a nother table as forien key in my custom databse.

could anyone let me know how i can do that

many thanks

Old October 5th, 2006, 03:41 AM
Friend of Wrox
Join Date: May 2006
Posts: 107
Thanks: 1
Thanked 8 Times in 7 Posts

Once the user has logged in then you can find out User.Identity.Name

You can then use this to return the UserId and therefore reference to aspnet_Membership, aspnet_sersInRoles etc.

If anyone knows a more elegant way then please post it here as I would also be interested

Old October 5th, 2006, 04:04 AM
Authorized User
Join Date: Aug 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to hcusto

First include "System.Web.Security" namespace

using System.Web.Security;
then in your method (function) where you want to get user id write:


if you want to add it to the string you must convert it to string but first check if the user id logged in
string userID;

if (User.Identity.IsAuthenticated)
      userID = Membership.GetUser().ProviderUserKey.ToString();
Hope that this helps,

Old March 15th, 2007, 12:17 AM
Registered User
Join Date: Mar 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to surekha

    I am also trying to get userId. I am using the following command:
I am assigning this value to a guid variable. But, I am getting a error like:

System.NullReferenceException was unhandled by user code
  Message="Object reference not set to an instance of an object."

Hope someone will help me.

Old July 12th, 2007, 04:50 PM
Authorized User
Join Date: Jul 2003
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Tremmorkeep Send a message via MSN to Tremmorkeep Send a message via Yahoo to Tremmorkeep

checking to see if the user is authenticated is critical at this point, my guess is that you dont have a user auth. so you're trying to get a providerkey for a null user. GetUser() also accepts a string argument so you can specify which user you want (ie GetUser("Steve") if you are editing data for users on your site.

Hope that helps.

Similar Threads
Thread Thread Starter Forum Replies Last Post
Get my Anonymous username or userID Maxxim ASP.NET 2.0 Professional 7 October 21st, 2007 08:17 AM
UserId/Computer Name mrookey Dreamweaver (all versions) 1 August 2nd, 2005 11:47 AM
UserId/Computer Name mrookey SQL Server ASP 1 August 2nd, 2005 07:23 AM
Insert News UserId -1 seanmayhew BOOK: ASP.NET Website Programming Problem-Design-Solution 1 November 14th, 2004 08:57 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.