I want to secure specific folders and resources in my application that are outside of the routes for my mvc application. I want these resources to only be available to authenticated users (which role is not of concequence as long as they are authenticated).
Initially it seemed that the UrlAuthorizationModule would be the answer. I followed this article, Understanding IIS 7.0 URL Authorization, and I can get the module to work in the sense that it responds to the configuration elements in the web.config
.
My current problem is that I think it is enacting the rules based on the anonymous user in IIS and not the authenticated user in asp.net identity.
Test Environment
I use a standard html
file for testing instead of trying to load a script as this would also be loaded outside of the MVC pipeline.
- In
Visual Studio 2015
.- New default
.net 4.6.2
web project - MVC template
- Authentication =
Individual User Accounts
- New default
- IIS 8 (for testing outside Visual Studio)
- Authentication -> Anonymous Authentication (enabled)
Add to web.config
<configuration>
...
<location path="Data">
<system.webServer>
<security>
<authorization>
<clear/>
<add accessType="Deny" users="*"/>
<add accessType="Allow" users="?"/>
</authorization>
</security>
</system.webServer>
</location>
...
</configuration>
Add to folder structure
/Data/Protected.html // this file just has some basic Hello World content to display so you can see if it is loaded or not.
Observed Results
- With this configuration everything in the
Data
path is always denied, it does not matter if the user is authenticated or not. - The same is true if I switch the 2 lines for
Deny
andAllow
in theweb.config
. - If I completely remove the line with
Deny
then access is always allowed even when the user is not authenticated. - If I add a role and use
roles
with the role name instead ofusers
attribute the role is also completely ignored.
Now What?
What am I missing? How can I get the Url Authorization module to work with MVC/WebAPI and ASP.NET Identity Individual user accounts
or is this simply not doable?
I am open to alternative ideas as well, maybe the answer is to write a custom HttpModule
or HttpHandler
?
Side notes
Why & Specifics
These resources are javascript files, in short only a portion of the scripts should be available to unauthenticated users. There are 2 directories in the root, one for the authenticated part of the app and one for the non-authenticated part of the app. The reason for this has nothing to do with user authorization or security in the application, it is to limit the exposed surface area of the application to non-authenticated requests.