How to use ASP.NET Membership for User Defined Permissions
<p>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:
Collapse | Copy Code</p>

<pre><code>Guid currentUser = (Guid)Membership.GetUser().ProviderUserKey;
int[] accessible = (from p in context.Permissions
                         where p.UserId == currentUser
                         select p.ContentId).toArray();
</code></pre>

<p>Then to get the content for the current user, something like this:
Collapse | Copy Code</p>

<pre><code>IEnumerable&lt;content&gt; content = context.Content
            .Where(x =&gt; x.PublicAccess &lt; 3 
            || accessible.Contains(x.ContentId));&lt;/content&gt;
</code></pre>

<p>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?</p>
