我有一个Web服务器,用户可以在其中下载针对每个用户特定的文件。为确保每个用户只能下载自己的文件,他们必须通过基本认证进行认证。因此,对于每个用户,服务器上都有一个windows用户帐户,具有对用户特定文件夹的读取权限。Web.config允许特定用户的位置访问
现在我想将此功能移到另一台服务器。我不想为用户创建Windows帐户,但仍保留基本身份验证。所以我使用Custom Basic Authentication HTTP Module结合Custom MembershipProvider,让我在web.config中定义用户。
认证工作得很好,但无论使用哪种jack
或jill
登录后(见的web.config)我能够访问这两个位置Dir1
和Dir2
。如果我在位置标签中注释掉<allow users="jack" />
部分,情况也是如此。
附加信息: 我创建了一个Default.aspx文件,并添加了
<% Response.Write(HTTPContext.Current.User.Identity.Name) %>
返回取决于谁登录正确的用户名
<% Response.Write(HTTPContext.Current.User.Identity.IsAuthenticated) %>
,则返回true。
我有什么做的,只有jack
能够访问(=下载文件从)Dir1
只有jill
能够访问(=从下载的文件)Dir2
而不是倒过来?
编辑:我试图添加web.config文件为每个子目录,而不是由utkai提到的位置标记 - 具有相同的结果。每个用户都可以访问任何目录。
这里是我的Web.config文件:
<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>
我需要一些时间进行我的研究工作。将尽快更新。 – Pankaj 2012-05-02 06:21:44
**我可以访问位置Dir1和Dir2 **您的Web服务器IIS中是否启用了目录浏览功能? – Pankaj 2012-05-02 14:30:10
不,我没有启用目录浏览。我的意思是我可以查看/下载这些目录中包含的文件,而不管用户登录的是什么。 – 2012-05-02 15:29:34