How to Filter result in MVC 4 based on user

前端 未结 7 791
面向向阳花
面向向阳花 2020-12-13 22:26

I have a custom authenticantion, when user logs in, I keep the necessary information on Session/Cache...

So, I have some Views with DropDowns that must show data fil

7条回答
  •  醉梦人生
    2020-12-13 22:48

    best way: get a cached list of all users. +: database efficient. -: uses lots of memory if big table. -: result not up to date (adjust cache time).

    In OData there is a database request filter which does this filter, but it is not intended to be used the way you want. It's here to protect against errors in stored procs and queries which returns rows that are not authorized for this user. This is a 2nd level of protection against data "leaks".

    var model = new Model(userId)
    

    elsewhere:

    Model(Guid userID)
    {
        MyList = CacheStore.Get("allUsers", () => repository.GetAll())
                    .Where(x => x.Id == userId).ToList();
    }
    

提交回复
热议问题