Prevent a file (pdf) from being served in asp.net

前端 未结 2 1988
迷失自我
迷失自我 2021-01-23 09:10

I\'ve got a legacy flash app (no access to the source) that when it completes it opens a pdf in a new window automatically.

Is there some way to prevent this one file at

相关标签:
2条回答
  • 2021-01-23 10:00

    You can drop a web.config in that folder which will prevent the files from being accessed unless they are in a specific role:

    <configuration>
        <system.web>
            <authorization>
               <allow roles="WHATEVER-ALLOWED-ROLES"/>
               <deny users="*"/>
            </authorization>
        </system.web>
    </configuration>
    

    If you only want to lock down that specific file you can wrap that <system.web> with <location path="filepath-and-name">

    This will likely require you to add the following handler to your root web.config in the "handlers" section, as usually IIS will serve up the file before ASP.NET touches it. This will make PDFs go through ASP.NET which can then handle the Role restrictions from above:

    <add name="PDFHandler-Integrated" path="*.pdf" verb="GET" type="System.Web.StaticFileHandler" modules="ManagedPipelineHandler" requireAccess="Script" preCondition="integratedMode" />
    
    0 讨论(0)
  • 2021-01-23 10:02

    You could lock the file down on the web server or delete it? If you can't alter the source you can't prevent the window.open from happening, but you can prevent the delivery.

    0 讨论(0)
提交回复
热议问题