Home > Mobile >  Best Practice to access Data related to another User
Best Practice to access Data related to another User

Time:09-15

Good evening I have an .NET Core MVC C# application that involves data stored for a child (ApplicationUser and a User Table - Role= "Child"). Parents/Guardians can create a profile (ApplicationUser and Parent Table). They can only see their children data.

What's the best way to "store" the current child ID they are viewing until they "switch" some way to another child ? Do you guys use cookies ? TempData? Viewbags ? Maybe a clean example I can look at ?

What's your strategy to store their first Child ID and take them to a default View for that child?

Thank you !

CodePudding user response:

You can store child ID list in HttpContext.Session.

////  Child IDs 
List<string> Ids= new List<string>();

//// To set value in session
HttpContext.Session.Set<List<string>>("child_ids", Ids);

//// To Get Value from Session
List<string> getIds = HttpContext.Session.Get<List<string>>("child_ids");

Then you can create custom policy to access their children data.

  • Related