使用Web.config阻止访问子目录

我有我的ASP.NET项目中包含实用程序文件的子目录。 在运行时,代码需要它们,但我不希望它们在Web上可见。

什么是Web.config文件中的语法来阻止对所有用户访问单个子目录及其所有内容?

IIS 7有一个新的“请求筛选”function。 您可能想要使用隐藏段configuration:

<configuration> <system.webServer> <security> <requestFiltering> <hiddenSegments> <add segment="BIN"/> </hiddenSegments> </requestFiltering> </security> </system.webServer> </configuration> 

这导致http:// yoursite / bin不可用(但是http:// yoursite / binary仍然可用)

查看: http : //learn.iis.net/page.aspx/143/how-to-use-request-filtering

你的问题是,如果IIS只是返回文件,ASP.Net永远不会有机会干涉。 我相信这可以通过启用基于表单的身份validation和相当混乱,但我只是将文件移动wwwroot文件夹之外。

JR

这应该工作:

 <configuration> <location path="FolderName"> <system.web> <authorization> <deny users="*"/> </authorization> </system.web> </location> </configuration>