Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
|
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 February 21st, 2013, 07:46 PM
Authorized User
 
Join Date: Feb 2013
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
Default When & where to get the UserID of the Logged-In User

Imar:

I have placed the following code in the Login.LoggedIn event:

Code:
 Guid currentUserId = (Guid) Membership.GetUser().ProviderUserKey();
Suprisingly, this returns a null value.

If I run the same code in the Page Load event of the page pointed to by the Login component's "DestinationPageUrl" it returns the correct value. Am I missing something? I thought that the UserId would be available in the "LoggedIn" event.

Thanks,

Robin Howard
 
Old February 21st, 2013, 07:55 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

LoggedIn fires after the post back and late in the page life cycle. That means that at that point the authentication hasn't been applied to the current request. Either redirect to another page (after which it will work), or use something like this:

Membership.GetUser(Login1.UserName)

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 February 26th, 2013, 04:17 PM
Authorized User
 
Join Date: Feb 2013
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
Default UserId of logged-in user

Thank you.





Similar Threads
Thread Thread Starter Forum Replies Last Post
to keep the user logged in until he sign out sarah lee ASP.NET 1.0 and 1.1 Basics 14 December 14th, 2006 11:55 AM
user logged jonyBravo Access 6 November 27th, 2006 09:14 AM
Reference UserID of logged in user radiohalo5 BOOK: ASP.NET Website Programming Problem-Design-Solution 2 February 7th, 2006 06:23 PM
Getting the name of the logged on user Grahame2003 C# 2 March 4th, 2004 04:48 AM





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