简体   繁体   中英

ASP.NET failing to make folder not accessible

I have a C# Webform application.

It contains a Report folder inside it Which contain some pdf files.

My application will show these reports on demand.

But I do not want someone to access these by typing the direct url

Eg: www.abc.com/Reports/a.pdf

I created the following Web.config inside the report folder:

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

Still, when testing I can access pdf files directly.

Also per business rules, I cannot use Form Authentication.

<system.web> controls configuration of the ASP.NET pipeline, not IIS. If you're running under IIS then ASP.NET will not be invoked for static file requests, such as the PDF file you mentioned.

To deny those requests use <system.webServer> instead. See this QA: How to make IIS7 stop serving a folder?

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

Note that <system.webServer> requires IIS7 or later (Windows Server 2008). If you're running IIS6 (Windows Server 2003 or Windows XP) then this won't work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM