我目前正在阻止匿名用户访问我的根应用程序。
/web.config
<system.web>
<authorization>
<deny users="?" />
</authorization>
</system.web>
但我允许匿名访问公共(public)资源(图像、CSS 等):
<location path="Images">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
现在,我想添加一个匿名用户应该可以访问的虚拟目录。我添加了一个基于图像路径的配置,但是每当我尝试访问该位置时,我都会被重定向到带有
ReturnURL
的登录页面设置为虚拟目录。 <location path="virtualDirectory">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
此外,我试图在我的虚拟目录的 web.config 中指定全局授权,但得到一个错误,说我只能拥有一次
/virtualDirectory/web.config:
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
当我的根应用程序阻止匿名访问时,如何允许匿名访问虚拟目录?
最佳答案
在你的全局 web.config 中封装
<system.web>
<authorization>
<deny users="?" />
</authorization>
</system.web>
和
<location path="." inheritInChildApplications="false">
<system.web>
<authorization>
<deny users="?" />
</authorization>
</system.web>
</location>
这意味着 - 仅在根应用程序中强制执行授权,而不是对子应用程序。
关于asp.net - 如何允许匿名用户访问虚拟目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39374517/