Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > ASP.NET 4 General Discussion
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 20th, 2011, 08:23 AM
Registered User
Points: 10, Level: 1
Points: 10, Level: 1 Points: 10, Level: 1 Points: 10, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2011
Location: New Delhi, India
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
Reply With Quote
  #2 (permalink)  
Old September 20th, 2011, 02:40 PM
Imar's Avatar
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
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!
Reply With Quote
The Following User Says Thank You to Imar For This Useful Post:
Sapan (September 21st, 2011)
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 07:00 AM.


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