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

November 28th, 2006, 05:51 PM
|
|
Registered User
|
|
Join Date: Nov 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Setting logged in UserName to Session ID
Hi, I'm new to ASP.NET but have been using classic asp for years. Anyway...
How do I set the logged in username to the Session ID? I want to track the user over several pages so they can update their own information in several tables.
Essentially, use the SQL Select statement to bind to the session variable to extract data from the table and likewise update or insert into the various tables.
If there is another way to do it using the built-in ASP.NET Log In controls, I'd be happy to hear it.
Thanks
|
|

November 28th, 2006, 06:04 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
You can get the user's ID from the MembershipUser's ProviderUserKey.
Take a look at my last post in this thread for an example...
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
|
|

November 28th, 2006, 09:33 PM
|
|
Registered User
|
|
Join Date: Nov 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks Imar for the help.
But I'm wondering, how come I can't just set the session variable from the <asp:loginName> control?
It seems odd that a whole round trip with lots of extra typing is needed to do something so simple? Or am I not doing it right? Or do I have to wait for ASP.NET 3.0? :)
Thanks again for your help.
|
|

November 29th, 2006, 10:45 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
You can't get the user's ID from that control, but you could access the user's name if you want. So, you could do what you want but use the name instead.
However, that way you're sort of bypassing the features that .NET offers you. The GetUser() method I mentioned always gives you access to the currently logged on user. That way, you don't need to keep track of the user in your own session variables. Isn't that much easier?
You could shield the two lines of code in a single helper property that returns the user object for you or you could combine the two lines of code in a single call. Then you'll have pretty much the same code as you would use when using a session variable.
Cheers,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
|
|

November 29th, 2006, 12:15 PM
|
|
Authorized User
|
|
Join Date: Sep 2006
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi , u can use user.identity.name to get the user name
eg .
session['username'] = user.identity.name
|
|

November 29th, 2006, 12:25 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Either way, why would you want to store that value in a session variable? What's the point in creating additional session variables when you can access the user's name from the Identity object or from a MembershipUser object??
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
|
|

November 29th, 2006, 12:36 PM
|
|
Authorized User
|
|
Join Date: Sep 2006
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi IMAR , Sure , Ur are correct. But its still old 'classic asp mind' for many.
|
|

November 29th, 2006, 01:11 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
I agree. That makes it even more important to show how you can accomplish the same thing using new techniques.... ;)
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
|
|

November 29th, 2006, 01:58 PM
|
|
Registered User
|
|
Join Date: Nov 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks again, I guess it's back to the books.. :)
|
|
 |