tl;dr: Why does
<allow users="?">
work on IIS Express, but not on IIS?
Background
I have a new asp.net web-forms project. When running locally on Windows 7 IIS Express, i can block "all users" from accessing the site by adding a deny *
rule to web.config:
web.config
<configuration>
<system.web>
<authorization>
<deny users="*" />
</authorization>
</system.web>
</configuration>
this causes me to be denied access:
And so that makes sense.
I can deny access to anonymous users
I the web.config, i can block access to anonymous users, by using the ?
marker, rather than the all (*
) marker:
<authorization>
<deny users="?" />
</authorization>
And because i am not authenticated, i will again be 401
Unauthorized:
And that makes sense.
Allow anonymous
I can allow anonymous access, by changing the deny
in web.config to allow
:
<authorization>
<allow users="?" />
</authorization>
And now I am brought right to the homepage:
and that makes sense.
But doesn't work on IIS
The above works on IIS Express. But when i publish to Windows Server 2012 R2 IIS 7.5, trying to allow
anonymous (?
) users does not work:
That makes no sense:
- works on IIS Express
- fails on IIS 7.5
Try allowing everyone
Rather than:
- allowing just anonymous users (
?
) - i can try to allow all users (
*
)
i change web.config again to allow everyone (*
):
<authorization>
<allow users="*" />
</authorization>
And locally i can still access the site:
but once i publish to IIS 7.5 it still fails:
What's going on?
I'm not doing anything wrong. So what do i need to change?
Initially i created an empty web-site, and started adding things to it. Later, i need to create real web-site (with pages that displayed information, and buttons to click), so i started over with an Empty Web Forms web-site.
My feeling is that Owin broke everything.
Nevertheless, what is going on?
Solution
I found it. There are some settings about a web-site that do not go with the web-site. That is, there are configuration options about a web-site that you cannot configure through web.config
, or any other file in the web-site's folder. In particular:
I don't know where IIS stores the use of anonymous authentication. But without anonymous authentication, IIS is unable to realize that an anonymous user is anonymous.
Enabling anonymous authentication:
causes IIS to realize that anonymous users are anonymous.
That explains:
- why it worked on IIS Expres
- why it didn't work on IIS 7.5
- why it still didn't work when both web-sites have the exact same set of configuration files
It doesn't explain why IIS doesn't treat anonymous users as anonymous when anonymous authentication is not enabled; but that's another issue for another day. If you've read down to here, you can copy-paste everything i just said, and get the accept. Otherwise i'll have to wait two days to answer it myself. Better you get the rep.