Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB 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
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 31st, 2012, 10:42 AM
Registered User
Points: 26, Level: 1
Points: 26, Level: 1 Points: 26, Level: 1 Points: 26, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2012
Location: San Diego, CA
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default ASP.Net Membership - Foreign Key

Imar, this question is not directly an issue with the book but rather a related issue that I was wondering if you will be kind to point me to a place to the right direction. I am building the Planet Wrox website and as well I am building a small website to make sure I am grabbing the concepts. In my application I have two conceptual tables: Bill and Users.

In the Bills table, I have columns like Bill ID, Bill Name, Bill Category, FK_User_ID and this FK_User_ID points to the user ID of my conceptual User table. Now in reality I have used the ASP.Net Membership instead of my conceptual user table. My question is how can I retrieve or reference the user ID of a user from Membership so I can reference it in my sqldatasource query. The goal is to show in the GridView and DetailsView only the tuples from the Bills table where the FK_user_ID matches the current user.

I have read up to chapter 13, and I have also jumped to chapter 16 but still struggling to find the answer, do you think I will find my answer in chapter 17 (Personalization) or if I need to read this in msdn, please point me to the right direction.
Thanks

Valentine
Reply With Quote
  #2 (permalink)  
Old September 1st, 2012, 06:45 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi Valentine,

The MembershipUser class has a ProviderUserKey property that returns the unique ID of the user from the database.

Something like this:

Code:
 
Guid userId = (Guid)Membership.GetUser().ProviderUserKey;
should give you the unique ID of the currently logged in user.

However, Microsoft recommends to not use this key and treat it as internal. Instead, you should use a combination of the user name and the application name. If you only store data of one application in your database, you can ignore the application name part.

You retrieve the name of the user from User.Identity.Name. Chapter 17, page 642 shown an example where the user name is used to link a photo album to a user.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #3 (permalink)  
Old September 1st, 2012, 10:34 AM
Registered User
Points: 26, Level: 1
Points: 26, Level: 1 Points: 26, Level: 1 Points: 26, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2012
Location: San Diego, CA
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks a lot, I will give it a try and hope to get it work

Valentine
Reply With Quote
Reply


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
Foreign Key to multiple tables maskoulis SQL Server 2008 1 November 29th, 2010 05:19 PM
Foreign key not updating with Primary key xavier1945 BOOK: Access 2003 VBA Programmer's Reference 2 July 4th, 2007 09:48 PM
Composite Foreign Key bijgupt SQL Server 2005 6 May 4th, 2007 08:46 AM
FOREIGN KEY and PRIMARY KEY Constraints junemo Oracle 10 June 15th, 2004 01:00 AM
Foreign Key Problem re_anu SQL Server 2000 1 September 26th, 2003 10:58 AM



All times are GMT -4. The time now is 10:17 PM.


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