我可以在 web.config 位置路径属性中使用通配符吗? [英] Can I use wildcards in the web.config location path attribute?
问题描述
在 IIS 7 中,我尝试拒绝所有用户访问所有扩展名为 .xml 的文件.
In IIS 7 I try to deny access to all files with the extension .xml for all users.
我在 web.config 文件中尝试了以下设置:
I tried the following setting in my web.config file:
<location path="*.xml">
<system.web>
<authorization>
<deny users="*"/>
</authorization>
</system.web>
</location>
但随后获取任何文件都会导致内部服务器错误.
But then getting any file results in an internal server error.
如果我拒绝访问单个文件,它会起作用,但这个解决方案不会给我带来太多好处,因为我事先并不知道所有 .xml 文件.
It works if I deny access to the individual files but this solution does not buy me much as I do not know all .xml files in advance.
推荐答案
试试这个:
<configuration>
<system.web>
<httpHandlers>
<add path="*.xml" verb="*"
type="System.Web.HttpNotFoundHandler" />
</httpHandlers>
</system.web>
</configuration>
顺便说一句,您也可以将所有 xml 文件存储在 App_Data 目录.在此目录中存储任何类型的文件都不会提供给网络.
By the way you could alternatively store all of your xml files within the App_Data directory. Storing files of any type in this directory will not be served to the web.
这篇关于我可以在 web.config 位置路径属性中使用通配符吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!