简体   繁体   English

阻止在asp.net中提供文件(pdf)

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

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. 我有一个遗留的Flash应用程序(无法访问源代码),当它完成时会自动在新窗口中打开pdf。

Is there some way to prevent this one file at this one specific location from opening (again, keeping in mind I cant edit the flash) 有没有办法阻止这个特定位置的这个文件打开(再次,请记住我不能编辑闪存)

So it opens to http://site.com/Files/Video/Completion.pdf directly in the browser, no handler or anything to change. 所以它直接在浏览器中打开http://site.com/Files/Video/Completion.pdf ,没有处理程序或任何要更改的内容。

You can drop a web.config in that folder which will prevent the files from being accessed unless they are in a specific role: 您可以在该文件夹中删除web.config,这将阻止文件被访问,除非它们处于特定角色:

<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"> 如果您只想锁定该特定文件,可以使用<location path="filepath-and-name"><system.web>包装起来

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. 这可能需要您在“处理程序”部分中将以下处理程序添加到根web.config中,因为IIS通常会在ASP.NET触及之前提供该文件。 This will make PDFs go through ASP.NET which can then handle the Role restrictions from above: 这将使PDF通过ASP.NET,然后可以从上面处理角色限制:

<add name="PDFHandler-Integrated" path="*.pdf" verb="GET" type="System.Web.StaticFileHandler" modules="ManagedPipelineHandler" requireAccess="Script" preCondition="integratedMode" />

You could lock the file down on the web server or delete it? 您可以将文件锁定在Web服务器上或删除它吗? If you can't alter the source you can't prevent the window.open from happening, but you can prevent the delivery. 如果您无法更改源,则无法阻止window.open发生,但您可以阻止传递。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM