View Single Post
  #2 (permalink)  
Old September 20th, 2011, 02:40 PM
Imar's Avatar
Imar Imar is offline
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts

Hi there,

It depends a bit on your data access technology, but it's common to take the user's name / identity into account as well as the role membership. In pseudo code the following LINQ query would accomplish this:

bool userIsAdministrator = User.IsInRole("Administrators");
var whatever = from a in Articles
    where a.CreatedBy == User.Identity.Name || userIsAdministrator
    select a;
This selects all articles that belong to a user, or really al articles when the user is an admin.

You can do similar stuff for direct SQL or other database access methods.

Hope this helps,

Imar Spaanjaars
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
The Following User Says Thank You to Imar For This Useful Post:
Sapan (September 21st, 2011)