How do you achieve field level security in ASP.Net?

I have a .aspx form with 20 fields that need to be disabled based on the user role and order entry status. Currently, the application has 5 roles and 3 statuses, so I have 300 different possible conditions that I have to consider.

My first thought is to store each permutation in a table, and then set the fields when the page loads by cycling through the fields. Is there a better way? Please note that I am using .Net 2.0 and NOT MVC.

+5
source share
3 answers

I would probably save the details of each field, and then the roles and status that can edit them, and do it that way.

What are the rules for the system? Basically, are there really 300 possible conditions? Or are certain fields really only available for a specific status, and only some roles can edit these fields? Or are some specific fields available for certain roles?

If it were more of the first, I would probably have something like this:

Three primary tables (simplify expansion if you add a field, role, or status):

  • Fields
  • Roles
  • Status

Then two link tables:

  • Field.Id and Role.Id
  • Field.Id and Status.Id

, , , , - - .

, , "/", , .

+5

, - CSLA. CSLA , get/set calls. :

Private mFirstName As String = ""
Public Property FirstName() As String
    <System.Runtime.CompilerServices.MethodImpl(Runtime.CompilerServices.MethodImplOptions.NoInlining)> _
    Get
        CanReadProperty("FirstName", True)
        Return mFirstName
    End Get
    <System.Runtime.CompilerServices.MethodImpl(Runtime.CompilerServices.MethodImplOptions.NoInlining)> _
    Set(ByVal value As String)
        CanWriteProperty("FirstName", True)
        If value Is Nothing Then value = ""
        If Not mFirstName.Equals(value) Then
            mFirstName = value
            PropertyHasChanged("FirstName")
        End If
    End Set
End Property

CanReadProperty CanWriteProperty. , , /.

CanReadProperty CanWriteProperty , CSLA. AuthorizationRules, , / / . AuthorizationRules .

CanReadProperty CanWriteProperty / . :

FirstNameTextBox.ReadOnly = Not CanWriteProperty("FirstName", false)

, . CSLA, - Expert # 2008.

+3

. CSLA. .

0
source

All Articles