Anatolii Humennyi
Anatolii Humennyi

Reputation: 1856

ASP.NET Allow access to directory and inner files for specific user

There is a directory "Media" in the project folder. I want to make it and its inner folders and files available only for a specific user. I created Web.config in this directory with the following content:

<?xml version="1.0"?>
<configuration>
  <system.web>
    <authorization>
      <allow users="specific_user"/>
      <deny users="*"/>
    </authorization>
  </system.web>
</configuration>

After this when I browse this folder or inner folders it works correct (it redirects me to the login page):

http://localhost:56547/Media/

http://localhost:56547/Media/box/

But when I browse to the file in that directory it opens in a browser and ASP.NET doesn't perform redirection to the login page:

http://localhost:56547/Media/box/test.txt

How to enable authorization for all inner files in this directory also?

Upvotes: 0

Views: 580

Answers (1)

martinshort
martinshort

Reputation: 23

Depending on the version of IIS, you may need to use system.webServer instead.

See https://serverfault.com/questions/72680/iis7-how-to-block-access-with-a-web-config-file for more information and some useful options.

Upvotes: 1

Related Questions