Click here to Skip to main content
15,881,033 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
hi all
i am making program and make control of user to add data,edit or delete
the admin can make permission to each user
i want when user login and try to add, edit or delete check if he has a permission or not but i do not know how to make check in all forms in program
please can any one help me in code how to make this
Er. Tushar Srivastava 21-Sep-12 9:40am    
Are you talking about system admin or some local admin of that application?
shimaa010 21-Sep-12 9:42am    
some local admin of the application

Unlike other answers, pretty complex ones, I have a practical and simple approach: don't do defensive programming, do offensive. Simply do this operation under try-catch block. If the permission denied exception is not thrown, the user has the access, and the operation is already done. If it was thrown — inform the user of the failure and its reason.

As simple as that.

Share this answer
fjdiewornncalwe 28-Sep-12 15:24pm    
+5. The proper approach to this.
Sergey Alexandrovich Kryukov 28-Sep-12 15:52pm    
Thank you, Marcus.
[no name] 28-Sep-12 15:56pm    
Hey Sergey...could you show how to do this with some code will very help full for me also
fjdiewornncalwe 28-Sep-12 16:04pm    
// Try to perform the action.
catch( Exception error )
// If the error type is correct for a user is unauthorized situation you have successfully stopped them from performing the task...
Sergey Alexandrovich Kryukov 28-Sep-12 16:11pm    
Yes, this kind of code.
Thank you, Marcus.
Hi Friend,
This can help you. I will not be posting direct codes, but I will be providing you with the hints to find your path.
See, Since you have some local Admin and users, the solution boils down to just testing a single variable.
1. See, define a variable of int type...

2. Set few codes, viz.. 01 = ADD ONLY (ie. the user can only add the data entry)

3. Similarly, setup few codes... 01, 02, 03, 04....

4. Now, when a user logs into his/her account, this variable will take any of the above values.... Now you can define this variable globally, so, any of the form can read this variable or more better, define it into a class called User class.

5. Now, based on this code, the program can simply provide authority to the user.

Hope, that this can help you.

Tushar Srivastava
Share this answer
shimaa010 21-Sep-12 10:02am    
ok thank u
Er. Tushar Srivastava 21-Sep-12 10:04am    
Oh! it's all right :-)
[no name] 28-Sep-12 15:54pm    
i think its very nice and simple

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