加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 如何允许匿名用户访问虚拟目录

发布时间:2020-12-16 07:13:24 所属栏目:asp.Net 来源:网络整理
导读:我目前阻止匿名用户访问我的根应用程序. /web.config system.web authorization deny users="?" / /authorization /system.web 但我允许匿名访问公共资源(图像,CSS等): location path="Images" system.web authorization allow users="*" / /authorization
我目前阻止匿名用户访问我的根应用程序.

/web.config

<system.web>
    <authorization>
      <deny users="?" />
    </authorization>
  </system.web>

但我允许匿名访问公共资源(图像,CSS等):

<location path="Images">
    <system.web>
      <authorization>
        <allow users="*" />
      </authorization>
    </system.web>
  </location>

现在,我想添加一个匿名用户可以访问的虚拟目录.我添加了一个基于Images路径的配置,但每当我尝试访问该位置时,我都会被重定向到登录页面,并将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>

这意味着 – 授权仅在root应用程序中实施,而不是针对子应用程序.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读