How to track and load a specific user's information?

526 Views Asked by At

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.

3

There are 3 best solutions below

0
On BEST ANSWER

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;
1
On

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.

0
On

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.