我试图获取默认情况下允许访问的最简单示例,除非通过 IIS 中特定目录的身份验证,否则拒绝访问。当你谷歌周围时,每个人都说这很简单:
<location path="~/pages">
<system.web>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</location>
不知怎的,这不适合我。
这是项目结构:
这是 Web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<authentication mode="Forms">
<forms loginUrl="~/" />
</authentication>
<authorization>
<!--<deny users="*"/>-->
</authorization>
<compilation debug="true" targetFramework="4.5.1" />
<httpRuntime targetFramework="4.5.1" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
<location path="~/pages">
<system.web>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</location>
</configuration>
目标是允许所有用户访问index.html并拒绝访问页面中的所有内容。
这是我的观察:
-
<!--<deny users="*"/>-->
未注释时有效。
- 如果没有的话它根本不起作用
<modules runAllManagedModulesForAllRequests="true" />
。删除这个,deny
在任何地方都不起作用。
- The
deny
in <location path="~/pages">
不起作用。设置路径为pages
or pages/secure.html
or ~/pages/secure.html
也不起作用。
这里有什么问题?
它不喜欢路径 "~/pages" 。以下对我有用
<configuration>
<system.web>
<authentication mode="Forms"/>
<compilation debug="true" targetFramework="4.5.1" />
<httpRuntime targetFramework="4.5.1" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"></modules>
</system.webServer>
<!-- note the change below -->
<location path="pages" >
<system.web>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</location>
</configuration>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)