Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is <deny users="?" /> included in the following example?

The ? wildcard represents unauthenticated users while * represents all users, authenticated and unauthenticated. My book shows the following example of URL authorization:

<authorization>   <deny users="?" />   <allow users="dan,matthew" />   <deny users="*" /> </authorization> 


But doesn’t the above code have the same effect as :

<authorization>   <allow users="dan,matthew" />   <deny users="*" /> </authorization> 

or did the author also include <deny users="?" /> rule for a reason?

like image 227
SourceC Avatar asked May 06 '09 21:05

SourceC


People also ask

What is deny users/>?

means deny unauthenticated users. The deny element adds to the mapping of authorization rules that is stored in the authorization element an authorization rule that denies access to a resource. This is the case when you want everybody to login before the can start browsing around your website.

Where do I add authorization in web config?

You can configure the <authorization> element at the server level in the ApplicationHost. config file, or at the site or application level in the appropriate Web. config file. You can set default authorization rules for the entire server by configuring authorization rules at the server level.


1 Answers

ASP.NET grants access from the configuration file as a matter of precedence. In case of a potential conflict, the first occurring grant takes precedence. So,

deny user="?"  

denies access to the anonymous user. Then

allow users="dan,matthew"  

grants access to that user. Finally, it denies access to everyone. This shakes out as everyone except dan,matthew is denied access.

Edited to add: and as @Deviant points out, denying access to unauthenticated is pointless, since the last entry includes unauthenticated as well. A good blog entry discussing this topic can be found at: Guru Sarkar's Blog

like image 80
Cyberherbalist Avatar answered Sep 22 '22 16:09

Cyberherbalist