2

I'm making a small portal in ASP.net (with C#.net4) where users can login and add, edit their personal information (PI). But I don't get how to load information (stored in a SQL server DB) in the page when a specific user is logged in.

For example: If Sam is logged in, he can view his PI. When Vicky is logged in, she can view her PI.

who can help me with this?

thanks in advance.

Paul Sasik
  • 79,492
  • 20
  • 149
  • 189
Thomas
  • 297
  • 1
  • 8
  • 21

3 Answers3

1

You need to retain the ID of the logged in user in a session variable and then use it to filter the query with which you fetch each user's info.

So if a user's ID is 278 then your query would run as:

SELECT first_name, last_name, * FROM user_table WHERE user_id = 278

From a session variable stored like:

Session["UserId"] = currentUserId;
Paul Sasik
  • 79,492
  • 20
  • 149
  • 189
0

The ASP.NET membership provider has already taken care of this for you. Have you considered using it? You can manage all of your authentication, permissions, roles, and access/edit profile information -- which you define. You access the data via the membership objects, and you won't need to write a single line of SQL to do it. It will save you loads of work instead of trying to reinvent the wheel.

George Johnston
  • 31,652
  • 27
  • 127
  • 172
  • Normally I would recommend this approach as well but Thomas is asking how to track the current user so that his/her individual info can be displayed properly. – Paul Sasik Jan 21 '11 at 14:09
0

Use the regular membership as described in the other answers. Then leverage the Profile system so that each user can view/edit their info when logged in (per the question). CAVEAT: ASP.NET profile system only works out of the box with the Website project template. If you want to use the Web Application project template, then follow the steps here:

ASP.NET: Web Site versus Web Application Project

When you have the profiles up and running, the profile data can be stored in session objects while the user is logged in.

IrishChieftain
  • 15,108
  • 7
  • 50
  • 91