Extra information on a user login

Asked

Viewed 90 times

0

My scenario is this::

The user will log into the system. Then a list of items will be displayed and he will choose a.

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

I don’t know how I can be doing this and I don’t know the technologies I might be using.

Currently for authentication of my projects I use Formsauthentication, however the same 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 the use of Session, but I think there’s a more appropriate technology.

  • 1

    I think you should review your question... It doesn’t seem to have any kind of research effort

  • @Cesarmiguel, I edited my question, but I don’t know what else to put.

  • How long do you need to store this information? For a few minutes? Months? Forever? This storage is only for user convenience to return to the site and review things as you selected them last time, or you will do some analysis or processing on your side?

  • @Renan, for a short time... The time that lasts the Formsauthentication....

  • That kind of made no sense. I think if you tell me what you’re going to do with this information it’s easier. But I’ll risk an answer.

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 these values only in 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. So it survives, for example, from one requisition to another. It stays on the server, so it can stay alive even if the user changes machine or access point.

An example of common use of sessions 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 you want to save only while the user is logged in.

To read 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, don’t forget to do an in-depth reading of official documentation, which also suggests other alternatives ;)

2

Browser other questions tagged

You are not signed in. Login or sign up in order to post.