Extra information on a user's login

0

My scenario is as follows:

The user will log into the system. Then it will display a list of items and it will pick one.

I then need the system to store the logged-in user and the item he chose.

I do not know how I can be doing this and I do not know what technologies I can use.

Currently, for authentication of my projects, I use FormsAuthentication , but the same I can not store more than one value (at least I do not know).

I found the following alternative:

Forms.SetAuthCookie (UserName + "|" + UserId, true);

if (HttpContext.Current.Request.IsAuthenticated)
{
    userId = Convert.ToInt32(HttpContext.Current.User.Identity.Name.Split('|')[1]);
}

I also thought about using Session , but I think there is a more appropriate technology.

    
asked by anonymous 30.09.2014 / 15:59

2 answers

5

If all you want is to have these values to use while the user is logged in - or if you want to use those values only on the next request - you can use the user session.

The session is an object that is unique per user. It is created when the user authenticates, and destroyed when it is disconnected. Thus it survives, for example, from one requisition to another. It stays on the server, so it can stay alive even if the user changes the machine or access point.

An example of common session usage is to store users' "grocery carts."

To play values in the session:

Session[nomeDaVariavel] = foo;

Where nomeDaVariavel is an arbitrary string, and foo is a value that you want to save only while the user is logged in.

To read the values, assuming they are strings:

string valor = (string)Session[nomeDaVariavel];

If the value has not been stored, it will be null.

That should be all you need. Good luck, and if that helped, do not forget to take a thorough look at official documentation , which also suggests other alternatives;)

    
30.09.2014 / 19:13
2

I also thought about using Session, but I think there is a more appropriate technology.

There is. It is the technology of Profiles .

Use your own implementation of ProfileBase to save the options for each user.

Use ProfileManager to manage the profiles of your users.

I recently answered some questions that might be of interest to you:

30.09.2014 / 19:08