How to limit the download of specified file types

I want to limit my web application so that .txt files cannot be downloaded / displayed. Can I configure this file in the web.config file?

I tried this in my configuration file:

<system.web>
    <httpHandlers>
        <add verb="*" path="*.txt" type="System.Web.HttpForbiddenHandler" />
    </httpHandlers>
</system.web>

... but it had no effect. I use IIS7, and the application is .NET3.5, can this have something to do with this? I know this really works .NEt 1.0 1.1 and 2.0.

I noticed in the documentation for this ( add httpHandlers ) Requirements :

Microsoft Internet Information Services (IIS) version 5.0, 5.1 or 6.0
.NET Framework version 1.0, 1.1 or 2.0
Microsoft Visual Studio 2003 or Visual Studio 2005

... which indicates that this is not supported in .NET 3 and IIS7 ...

Where is this indicated in IIS7?

+3
4

MS Support , : : ASP.NET .

IIS ASP.NET, web.config , : (nb dev IIS7 - )

<system.web>
    <httpHandlers>
        <add verb="*" path="*.ini" type="System.Web.HttpForbiddenHandler" />
    </httpHandlers>
</system.web>

httpHandlers Element, .NET :.NET ):

*. asax, *.ascx, *.master, *.skin, *.browser, *.sitemap, *.config, *.cs, *.csproj, *.vb, *.vbproj, *.webinfo, *.licx, *.resx, *.resources, *.mdb, *.vjsproj, *.java, *.jsl, *.ldb, *.dsdgm, *.ssdgm, *.lsad, *.ssmap, *.cd, *.dsprototype, *.lsaprototype, *.sdm, *.sdmDocument, *.mdf, *.ldf

EDIT: IIS IIS 7.0. IIS 7.0 , Integrated Mode ( ASP.NET), , <system.webServer>/<handlers> <system.web>/<httpHandlers>. @awe , .

! IIS 7.0

, <add> , - , 500 Internal Error

  <system.webServer>
        <handlers>
            <add name="IgnoreIni" verb="*" path="*.ini" type="System.Web.HttpForbiddenHandler" />
        </handlers>
    </system.webServer>
+8

OK. . .NET 3, web.config. <system.web><httpHandlers> <system.webServer><handlers> :

<system.webServer>
  <handlers>
    <add name="NoTxtAllowed" verb="*" path="*.txt" 
       type="System.Web.HttpForbiddenHandler" />
  </handlers>
</system.webServer>

, , Ahmad Mageed , , .NET 3 . , . , .NET 3.

EDIT: IIS 7.0 2 : . - ASP.NET IIS 7.0, , <system.webServer>/<handlers> <system.web>/<httpHandlers> ( Classic IIS).

:

+4

, IIS, .

+2

.config? .aspx?

0

Source: https://habr.com/ru/post/1716600/


All Articles