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 November 28th, 2006, 05:51 PM
Registered User
 
Join Date: Nov 2006
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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

  #2 (permalink)  
Old November 28th, 2006, 06:04 PM
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 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.
  #3 (permalink)  
Old November 28th, 2006, 09:33 PM
Registered User
 
Join Date: Nov 2006
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

  #4 (permalink)  
Old November 29th, 2006, 10: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

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.
  #5 (permalink)  
Old November 29th, 2006, 12:15 PM
Authorized User
 
Join Date: Sep 2006
Location: , , India.
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi , u can use user.identity.name to get the user name

eg .

session['username'] = user.identity.name

  #6 (permalink)  
Old November 29th, 2006, 12:25 PM
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

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.
  #7 (permalink)  
Old November 29th, 2006, 12:36 PM
Authorized User
 
Join Date: Sep 2006
Location: , , India.
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi IMAR , Sure , Ur are correct. But its still old 'classic asp mind' for many.

  #8 (permalink)  
Old November 29th, 2006, 01:11 PM
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

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.
  #9 (permalink)  
Old November 29th, 2006, 01:58 PM
Registered User
 
Join Date: Nov 2006
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks again, I guess it's back to the books.. :)

  #10 (permalink)  
Old November 30th, 2006, 05:04 PM
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

Good luck. You know where to come to when you need more help... ;)

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
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.
 


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
insert the username of the logged in user cesemj ASP.NET 2.0 Basics 6 February 12th, 2008 10:13 AM
Username of logged in user spardoe BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 4 August 18th, 2006 01:13 AM
setting a web control's ID programatically lcsgeek General .NET 3 January 24th, 2005 02:50 PM
Logged - in status without using session madhukp Classic ASP Basics 13 July 14th, 2004 05:05 AM



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


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