拒绝访问文件夹,但允许访问该文件夹中的文件 [英] Deny access to folder but allow access to a file inside that folder

查看:149
本文介绍了拒绝访问文件夹,但允许访问该文件夹中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想拒绝匿名用户访问文件夹"test",但排除并允许访问测试文件夹中的文件"webform1".为什么这不起作用?

I would like to deny anonymous users access to the folder 'test' but exclude and allow access to a file 'webform1' inside the test folder. Why does this not work?

<location path="test">
<system.web>
  <authorization>
    <deny users="?"/>
  </authorization>
</system.web>
</location>
<location path="test/webform1">
<system.web>
  <authorization>
    <allow users="*"/>
  </authorization>
</system.web>

这是一个示例Webforms项目的链接 https://github.com/uselesshasid/StackOverflow_Question_38597397

Here is a link to a sample webforms project https://github.com/uselesshasid/StackOverflow_Question_38597397

推荐答案

这可能是asp.net中的一个错误,它使用友好的url时会处理授权的方式.

This is probably a bug in asp.net, with the way it handles authorization when friendly url's are used.

我将web.config更改为按文件url的版本进行定义,并且可以正常工作.

I changed the web.config to define by versions of the file url, and it works.

<location path="test/webform1">
<system.web>
   <authorization>
     <allow users="*"/>
   </authorization>
</system.web>
<location path="test/webform1.aspx">
<system.web>
   <authorization>
     <allow users="*"/>
   </authorization>
</system.web>

这篇关于拒绝访问文件夹,但允许访问该文件夹中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆