How to deny access to folder or file

2019-02-23 19:30发布

问题:

I have an ASP.NET website and I need to block a specific folder named /swf.

This folder have a lot of swf files that cannot be accessed from unauthenticated users.

Ideas?

回答1:

Consider using the configuration/location nodes in your web.config. Details on MSDN

<configuration>
    <location path="MySubDirectory">
        <system.web>
            <authorization>
                <deny users="*"/> <!-- Denies all users -->
            </authorization>
        </system.web>
    </location>
</configuration>


回答2:

Thank you all, but doesn't work in my case.

These solutions you wrote works only to pages. When I try to access the swf or image file, it doesn't work:

site.com/swf/Page.aspx - WORK

site.com/swf/file.swf - DOESN'T WORK

I found the solution: How to secure access to SWF file using ASP.NET?



回答3:

There are several options explained here: http://support.microsoft.com/kb/815151

Also, if you haven't already, I strongly recommend reading up on ASP.NET Authentication here: http://msdn.microsoft.com/en-us/library/eeyk640h.aspx

Edit

Since you're using Forms authentication and want to deny anonymous users, then you can create a web.confic in the swf folder and put the following in the authorization section:

<authorization>
     <deny users="?"/>
</authorization>