What should be used instead of a session?

I am working on a project that I need to create a list of menus according to the profile of a registered user. But for now, I have to create this list every time the page loads, and this is not very good for my project.

What I want to do is get this list only when the user logs in and uses it every time I need it. My idea is to keep this list in Sessionwhen the user logs in. But I know that a session is not a good practice.

I tried to use session, cookie and OutputCachein ActionResult, but only the session works.

Is there a way to save my list in a "global variable" or something like that, and do I always need to use it?

+4
source share
3 answers

I can offer two options for your problem.

  • Use a Session object for each user. or
  • Use caching mechanism. If you have implemented some kind of caching mechanism in your application, you can create one object per user that saves the navigation menu (something like caching Redis, AppFabric or .NET).

An object associated with the menu should only create one time for the user (it can be created during login).

+2
source

, , / ( , - , JSON?), .

- .

+1

.

, Session. ? (SidebarViewModel) Session [ "sidebar" ] ', , , .

I tried using "OutputCache" (my own attribute class), but since my menu is ChildAction, I could not clear my cache when I log out, and this is not very good for a user who can change his own avatar whenever he wants. I also tried using the application, but it was almost the same session case.

PS: I don’t like sessions, but I think this is the best way at the moment.

0
source

All Articles