How can I limit asp.net control actions based on user role?

℡╲_俬逩灬. 提交于 2019-12-04 11:52:44

The best approach will be to add a property on a custom control saying Roles or something that will allow the users of such roles to view the control. Since, you do not have time for that you can make a helper method which will deal with the visible property of the control. Something like this:

<asp:Button id="UpdateButton" runat="server" Visible="<%# IsInRole("Admin") %>" /> 

You can also make your own helper method that checks for more criteria.

To display the controls, You could use asp:LoginView.

http://www.codedigest.com/Articles/ASPNET/78_LoginView_Controls_with_Roles_in_ASPNet_20.aspx

for "users that may know how to perform an action in the absence of a button",

you could use if User.IsInRole("Role_name") then ... before doing your update stuff. you could also add security to function by using :

<PrincipalPermission(SecurityAction.Demand, role:="Role_name")> _

http://www.4guysfromrolla.com/webtech/121901-1.2.shtml

Please take a look at these two great tutorials Written by Scott Mitchell , I am sure that It would be very useful.

http://www.asp.net/security/tutorials/user-based-authorization-cs

http://www.asp.net/data-access/tutorials/limiting-data-modification-functionality-based-on-the-user-cs

and for further Reading you can take a look at these series again written by Scott Mitchell

http://www.4guysfromrolla.com/articles/120705-1.aspx

One solution would be to write a few custom stored procedures on the database side. If you passed in a boolean flag for auth'ed vs. unauth'ed then your SQL code could handle which results are returned and which actions are performed.

However, if you envision many of your users being unauthorized, maybe you should use the session state to check a user's role, before you make a thousand calls down into your database.

Basically, you need to "conditionally bind" your grid to its datasource, determining which stored procedure to call by checking the user's role.

I hope this helps a bit!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!