What is a good design pattern for storing information about the last user of a user?

I am developing a function to store the latest date / time of entry into an ASP.Net application (MVC).

My first instinct was to save the value in the database against the user profile entry and update the value to the current date / time upon successful login. Of course, as soon as I record this value, the date and time of successful login to this session will be displayed on all pages.

Plan B: a field for recording a previous session and one for recording this session. When entering the system, save this date / time of the session in the "current" field and move the previously found value to the "previous" field (obviously). It is this field that provides my "last login" value.

Is this a better approach or can it be done more elegantly?

+5
source share
3 answers

Another approach is to read the last registration date / time from the user's record upon logging in and save it in the session or in the session cookie. Then update the user record with the current date / time. Then, on your pages, read the value stored in the session / cookie.

The old time will be deleted when the session ends, which usually occurs when the user needs to re-enter the system. It also has the advantage of speed and caching as it reads from a session / cookie.

But it depends on your setup and application, is it possible for you.

UPDATE

, ... / , . , / , cookie. / .

, , cookie cookie .

+4

...

  • , , , . " 5 ", . ( , , - script.)

  • global.asax Session_End ( - ). , , , Session_End , . , , , , , , Session_End , , Session_End .

  • - , - , asp.net , . ASP - , .

+1

, ?

/ blob . , .

My first thought was to simply use it Stack<T>to implement this, but although it is serializable, it does not provide any hooks that will automatically supersede the old values.

0
source

All Articles