我有一个可执行文件,我想限制谁可以下载。我有 UI 修剪到位,因此当用户无权下载可执行文件时链接不存在。我在 web.config 中设置了一条规则,以保护资源免受未经授权的下载,但它似乎不起作用。
<location path="Utilities/SomeTool.exe">
<system.web>
<authorization>
<allow roles="SomeRole" />
<deny users="*"/>
</authorization>
</system.web>
</location>
当我尝试下载资源时看到的是登录页面,如果用户不属于应该能够下载资源的角色,这是可以预期的。
我可以更改 web.config 中的规则,使其允许特定用户,并且我可以使用该特定用户访问可执行文件,但这不起作用,因为我需要为每个用户修改访问规则添加到角色中。
<location path="Utilities/SomeTool.exe">
<system.web>
<authorization>
<allow users="MyUserName"/>
<deny users="*"/>
</authorization>
</system.web>
</location>
我已经设置了 web.config 以利用 IIS7 中的集成管道,方法是按照此页面上的说明删除和重新添加模块列表。这应该将我的网站设置为将所有资源视为 ASP.NET 资源。
有人知道我在 IIS7 的配置中可能缺少什么来保护可执行文件吗?
我已经想到了可以实施的其他解决方案,以保护可执行文件免遭未经授权的下载,例如创建链接将调用并返回资源的 Web 服务。然后在 web 服务中,我可以在返回可执行文件之前执行用户角色的验证。但这似乎比我需要完成的工作要多。
这是我的 web.config 的 system.web 部分:
<system.web>
<compilation debug="false" targetFramework="4.0" />
<httpRuntime enableVersionHeader="false" requestValidationMode="2.0" />
<customErrors mode="RemoteOnly">
<error statusCode="404" redirect="~/MyErrorPage.aspx" />
</customErrors>
<authentication mode="Forms">
<forms timeout="60" ticketCompatibilityMode="Framework40" />
</authentication>
<authorization>
<deny users="?" />
</authorization>
<sessionState timeout="60" />
<membership defaultProvider="MyMembershipProvider">
<providers>
<clear />
<add name="MyMembershipProvider" type="MyMembershipProvider" applicationName="MyApp" />
</providers>
</membership>
<roleManager defaultProvider="MyRoleProvider" enabled="true" cacheRolesInCookie="true" cookieTimeout="60">
<providers>
<clear />
<add name="MyRoleProvider" type="MyRoleProvider" applicationName="MyApp" />
</providers>
</roleManager>
</system.web>
附带说明一下,当 web.config 在 Visual Studio 2010 中托管时,它可以与我的网站一起使用,但在 IIS7 中运行时会失败。
更新:我试图根据角色保护 *.html 和 *.aspx 页面的不同资源,我看到了同样的问题,即使用户确实属于适当的角色,也会被重定向到登录页面。
提前致谢。