One way to block access to a specific folder in your ASP.NET MVC website is by combining the <location> with an <authorization> section inside your web.config:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<configuration> | |
<location path="hiddenfolder"> | |
<system.web> | |
<authorization> | |
<deny users="*"/> | |
</authorization> | |
</system.web> | |
</location> | |
</configuration> |
In fact this is not the best approach as it is possible that this configuration is not applied when the ASP.NET pipeline is not invoked.
A better approach is to block the access at the IIS level by using the following configuration inside your web.config:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<system.webServer> | |
<security> | |
<requestFiltering> | |
<hiddenSegments> | |
<add segment="hiddenfolder" /> | |
</hiddenSegments> | |
</requestFiltering> | |
</security> | |
<system.webServer> |