使用web.config拒绝代码执行IIS7

时间:2011-04-10 19:03:20

标签: asp.net iis-7 web-config authorization iis-7.5

我想阻止用户在Web应用程序的上传文件夹(/ assets / public /)中运行特定扩展名。用户可以上传在上传期间也重新调整大小的图像文件。但为了更安全,我想拒绝像aspx,asp,php ......

这样的脚本

我有阻止每个扩展程序的当前代码,但我想允许像.jpg这样的扩展程序:

<location path="assets/public">
    <system.web>
        <authorization>
            <deny users="*"/>
        </authorization>
    </system.web>
</location>
<system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>

此外,用户没有FTP访问权限,应用程序已预先编译。

2 个答案:

答案 0 :(得分:0)

尝试

<httpModules>
    <clear />
</httpModules>

<location path="." inheritInChildApplications="false">
</location>

答案 1 :(得分:-2)

以下是我使用global.asax和路由解决这个问题的方法。刚刚添加了这些规则:

routes.MapPageRoute("any", "assets/public/{file}.{ext}", "~/e/404.aspx");
routes.MapPageRoute("any-sub","assets/public/{sub}/{file}.{ext}","~/e/404.aspx");

routes.Ignore("{any}.jpg");
routes.Ignore("{any}.png");
routes.Ignore("{any}.gif");
routes.Ignore("{any}.pdf");