Wrox Programmer Forums
|
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 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 August 31st, 2012, 10:42 AM
Registered User
 
Join Date: Jun 2012
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
 
Old September 1st, 2012, 06:45 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 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!
 
Old September 1st, 2012, 10:34 AM
Registered User
 
Join Date: Jun 2012
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





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





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