|
Authorizing Users and Roles
ASP.NET Permissible elements for authorization directives are either allow or deny. Each allow or deny element must contain a users or a roles attribute. Multiple users or roles can be specified in a single element by providing a comma-separated list.
The HTTP method can be indicated using the Verb attribute:
This example lets Mary and John POST to the protected resources, while only allowing everyone else to use GET. There are two special usernames:
URL authorization is computed hierarchically and the rules used to determine access are as follows:
The default setting in the machine-wide configuration file (machine.config) is to grant access to all users. Unless an application is configured to the contrary (and assuming that a user is authenticated and passes the file authorization ACL check), access is granted. When roles are checked, URL authorization effectively marches down the list of configured roles and does something that looks like the following pseudocode:
If User.IsInRole("ConfiguredRole") Then
ApplyRule()
End If
VB
What this means for your application is that you use your own class that implements System.Security.Principal.IPrincipal to provide your own role-mapping semantics, as explained in Windows-based Authentication. The following sample uses forms-based authentication services. It explicitly denies access to someone@www.contoso.com and anonymous users. Try logging into the sample with Username="someone@www.contoso.com" and Password="password". Access will be denied and you will be redirected back to the logon page. Now log on as Username="someone.else@www.contoso.com" and Password="password". You will see that access is granted.
|