- Forms Authentication
- Windows Authentication
Authorization is used where we want to restrict authenticated users from using some of the resources (web pages, or files etc) in the system. e.g. a general user of a website cannot access the page where an Administrator and delete and add new users. There are following types of authentication
- URL Authentication - it is resources based authentication where we define rules for specific resources in the system (in web.config) , if user tries to access something forbidden then the response depends on the authentication type used in the system. If we are using windows authentication then we receive a 401 page (Access Denied) and if we are using the Forms Authentication then we get the login page of the system.
Authorization Rules
- the authorization rules are in
in the tag of the web.config - inside
two basic tags are used and - look at the example below


<
<
<
Notes:
- in
and tags we define rules for users as well the roles in the system. - we can use as many
and rules as we want. - there is verb attribute in these rules in which we can define the type of HTTP request and set rules on it.
<
"?" indicates that the user should be authenticated and it represents all the unknown identities
THE BEST APPROACH FOR AUTHENTICATION IS TO DENY EVERYTHING FIRST AND THEN ALLOW SPECIFIC USERS.
we can use "*" in place of "?" which means everything can access everything in the system. but rule with a "*" is rarely required because its already present in machin.config file.
Note:
if we are using the "*" and "?" together then their order will really matter, if we are using "*" and "?" later that mean in top down rule parsing of asp.net it will encounter the "*" first and stop so any user will have access to everything. so if we are using these together then we should use "?" first always.
Examples
- Controlling Access to Specified Users
<deny users="?" />
<deny users="dan" />
<deny users="jenny" />
<deny users="matthew" />
<allow users="*" />
</authorization>the above users can also be given in comma separated list.
- Controlling Access to Specified Directories
The best way to control the access to specified directories is to create another config file and defined the respective rules. and leave the parent config file <autherization> tage empty.
- Controlling Access to Specific Files
To control access to specific files we define <location> tag inside the main configuration tage, its outside the <ststem.web> tag.
<location path="restrictedpage.aspx"><system.web>
<authorization>
<deny users="?" />
</authorization>
</system.web>
</location>
No comments:
Post a Comment