如何检查用户是否有权限 [英] how to check if user have a permission or not

查看:152
本文介绍了如何检查用户是否有权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好
我正在制作程序并控制用户添加数据,编辑或删除
管理员可以向每个用户授予权限
我想在用户登录时尝试添加,编辑或删除他是否具有权限的检查,但我不知道如何在程序中的所有表格中进行检查
请任何人在代码中帮助我如何制作此

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

推荐答案

与其他答案一样,非常复杂的答案,我有一种实用且简单的方法:不要做防御性的编程,不要做有攻击性的.只需在try-catch块下执行此操作即可.如果未抛出拒绝权限异常,则该用户具有访问权限,并且该操作已完成.如果引发了故障,请告知用户故障及其原因.
就这么简单.

—SA
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.

—SA


朋友,
这可以为您提供帮助.我不会发布直接代码,但会向您提供提示以找到您的路径.
请参阅,由于您具有一些本地Admin和用户,因此该解决方案可以归结为仅测试单个变量.
1.请参阅,定义一个int类型的变量...

2.设置一些代码,即.01 =仅添加(即用户只能添加数据条目)

3.同样,设置一些代码... 01,02,03,04 ....

4.现在,当用户登录到他/她的帐户时,该变量将采用上述任何值....现在,您可以全局定义此变量,因此,任何形式的表都可以读取此变量或更好地定义将其转换为名为User class的类.

5.现在,基于此代码,该程序可以简单地向用户提供权限.

希望对您有帮助.

问候
Tushar Srivastava
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.

Regards
Tushar Srivastava


这篇关于如何检查用户是否有权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆