Click here to Skip to main content
15,030,320 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a simple ASP.NET MVC 3 application. I have the database I designed for the application, which corresponds to a domain model (in an App.Domain assembly).
I auto-generated the Application Services Membership tables and added them to the application database. Membership creation is working fine.
I created a 'Permission' table which has a composite PK made up of UserId (from the auto-generated aspnet_Users table) and ContentId (from the Content table holding the application content).
The idea is to allow users to allocate permissions to other users for the content they create.
My plan is to then place logic in the Controllers that goes something like:
C#
Guid currentUser = (Guid)Membership.GetUser().ProviderUserKey;
int[] accessible = (from p in context.Permissions
                             where p.UserId == currentUser
                             select p.ContentId).toArray();

Then to get the content for the current user, something like this:
C#
IEnumerable<content> content = context.Content
                .Where(x => x.PublicAccess < 3 || accessible.Contains(x.ContentId));</content>


If I have made any sense, can anyone tell me if this is a normal way to handle user defined permissions.
Also, this code doesn't work because it won't cast the linq to an int[]. Any help with that?
Posted

1 solution

I think that is an acceptable way to handle what you are trying to do. Try using a list instead of an array it may fix your problem. See example code below.

C#
List<int> accessible = (from p in context.Permissions
                             where p.UserId == currentUser
                             select p.ContentId).toList();</int>
   
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900