Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > ASP.NET 4 General Discussion
|
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 20th, 2011, 08:23 AM
Registered User
 
Join Date: Sep 2011
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Default how to query database tables depending on the logged-in user.

Hello,
I would like to know how to limit a logged-in user to view and edit data that were entered by him only. I am not talking about personal information of each user that could be dealt with profiles. I am talking about any other data.
Additionally, I also want to know how can an another person, say a manager, can view all data entered by all users.
Any useful reply is welcome but since I am following Imar since asp.net 3.5 I would love to hear from him.
Thanks,
Sapan
 
Old September 20th, 2011, 02:40 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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:

Code:
 
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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
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!
The Following User Says Thank You to Imar For This Useful Post:
Sapan (September 21st, 2011)





Similar Threads
Thread Thread Starter Forum Replies Last Post
to keep the user logged in until he sign out sarah lee ASP.NET 1.0 and 1.1 Basics 14 December 14th, 2006 11:55 AM
user logged jonyBravo Access 6 November 27th, 2006 09:14 AM
Query database for List of tables & other details imsuneeta SQL Server 2000 2 January 18th, 2005 07:48 AM
Getting the name of the logged on user Grahame2003 C# 2 March 4th, 2004 04:48 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.