Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 4th, 2006, 05:32 PM
Authorized User
 
Join Date: Jul 2006
Location: , , United Kingdom.
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default Return UserId from aspnet_Users

Hi;

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

  #2 (permalink)  
Old October 5th, 2006, 03:41 AM
Friend of Wrox
 
Join Date: May 2006
Location: Northampton, United Kingdom.
Posts: 107
Thanks: 1
Thanked 8 Times in 7 Posts
Default

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

  #3 (permalink)  
Old October 5th, 2006, 04:04 AM
Authorized User
 
Join Date: Aug 2006
Location: Mostar, HNK, Bosnia and Herzegovina.
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to hcusto
Default

First include "System.Web.Security" namespace

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

 Membership.GetUser().ProviderUserKey;

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

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

  #4 (permalink)  
Old March 15th, 2007, 12:17 AM
Registered User
 
Join Date: Mar 2007
Location: hyderabad, ap, India.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to surekha
Default

Hi,
    I am also trying to get userId. I am using the following command:
(Guid)Membership.GetUser().ProviderUserKey
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."
  Source="App_Web_ghqgbxbt"

Hope someone will help me.

Thanks
  #5 (permalink)  
Old July 12th, 2007, 04:50 PM
Authorized User
 
Join Date: Jul 2003
Location: Ogden, Utah, USA.
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
Default

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


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 07:01 AM.


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