I have a webserver from where users can download files that are specific for each user. To be sure each user can only download its own files they must authenticate via Basic-Authentication. So for each user there is a windows-account on the server that has read permissions to the user specific folder.
Now I want to move this functionality to another server. I do not want to create windows accounts for the users but still keep the Basic-Authentication. So I use the Custom Basic Authentication HTTP Module in combination with a Custom MembershipProvider that lets me define users in the web.config.
The authentication works quite fine but after logging in with either jack
or jill
(see web.config) I'm able to access both locations Dir1
and Dir2
. This is also the case if I comment out the <allow users="jack" />
part in the location tags.
Additional Info: I created a Default.aspx file and added a
<% Response.Write(HTTPContext.Current.User.Identity.Name) %>
which returns the correct user name depending on who logged in.
<% Response.Write(HTTPContext.Current.User.Identity.IsAuthenticated) %>
returns True.
What do I have to do that only jack
is able to access (= download files from) Dir1
and only jill
is able to access (=download files from) Dir2
but not the other way round?
EDIT: I tried to add web.config files for each subdirectories instead of the location tags as mentioned by utkai - with the same result. Every user can access any directory.
Here is my Web.config file:
<configuration>
<system.webServer>
<modules>
<add name="CustomBasicAuthentication" type="LeastPrivilege.CustomBasicAuthentication.CustomBasicAuthenticationModule, LeastPrivilege.CustomBasicAuthenticationModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=F20DC168DFD54966"/>
</modules>
<security>
<authentication>
<customBasicAuthentication enabled="true" realm="TEST" providerName="AspNetWebConfigMembershipProvider" cachingEnabled="true" cachingDuration="15" requireSSL="false"/>
</authentication>
<authorization>
<deny users="?" />
</authorization>
</security>
</system.webServer>
<system.web>
<membership defaultProvider="AspNetWebConfigMembershipProvider">
<providers>
<add name="AspNetWebConfigMembershipProvider" type="LeastPrivilege.AspNetSecurity.Samples.WebConfigMembershipProvider, WebConfigMembershipProvider"/>
</providers>
</membership>
<authentication mode="Forms">
<forms>
<credentials passwordFormat="Clear">
<user name="jack" password="jack"/>
<user name="jill" password="jill"/>
</credentials>
</forms>
</authentication>
<authorization>
<deny users="?" />
</authorization>
</system.web>
<location path="Dir1" allowOverride="false">
<system.web>
<authorization>
<!-- <allow users="jack" /> -->
<deny users="*" />
</authorization>
</system.web>
</location>
<location path="Dir2" allowOverride="false">
<system.web>
<authorization>
<!-- <allow users="jill" /> -->
<deny users="*" />
</authorization>
</system.web>
</location>
</configuration>