【发布时间】:2012-04-16 23:01:24
【问题描述】:
我有一个网络服务器,用户可以从中下载每个用户的特定文件。为确保每个用户只能下载自己的文件,他们必须通过 Basic-Authentication 进行身份验证。因此,对于每个用户,服务器上都有一个 Windows 帐户,该帐户具有对用户特定文件夹的读取权限。
现在我想将此功能移至另一台服务器。我不想为用户创建 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>
【问题讨论】:
-
我的研究工作需要一些时间。很快就会更新你。
-
我可以同时访问 Dir1 和 Dir2 您是否在 Web 服务器 IIS 中启用了目录浏览功能?
-
不,我没有启用目录浏览。我的意思是我可以查看/下载这些目录中包含的文件,无论用户登录的是什么。
-
你有
download的链接还是直接输入url? -
我只是在地址栏中输入
http://localhost/Dir1/jack.txt之类的内容以进行测试。它有什么不同?
标签: asp.net permissions web-config