简体   繁体   中英

Encrypting src attribute of iframe control

I am using iframe to load a pdf file from a temporary location , which looks as shown below

<iframe id="myPDF" width="100%" height="100%" src="Config\Temp\tmp_report_0.pdf"></iframe>

this will load up a pdf file to browser window, inside the iframe. My question is how can i hide this 'src' value from being visible to user when they right click and select 'view source' from browser.

The intention is here to enrcypt/hide the 'src' value from users. Any suggestions?

You can use a generic handler to hide the actually file from location.

Inside your handler you serve the file base on a url parameter. Here is a basic example:

 <iframe id="myPDF" width="100%" height="100%" src="OpenReport.ashx?ReportId=2129938212"></iframe>

Now you can/must encrypt also the url parameter to avoid anyone download all your reports.

An example of handler to download the file : ASP.NET file download from server

From that you remove all the line that contains the attachment; filename= attachment; filename= so the file will be load on the inside of the iframe. Of course you can find many other examples.

You can use SECURITY property.

<IFRAME ID="myPDF"
        SECURITY="restricted"  
        WIDTH="100%"
        HEIGHT="100%" 
        SRC="Config\Temp\tmp_report_0.pdf" />

Or check this link Hide SRC tag

Is your PDF static or dynamic? If dynamic then would suggest to make httphandler which generates pdf and return url. Then add src attribute/modify src attribute using JavaScript. also, handler can be called using Javascript. Still this will not be hidden if user uses developer toolbar of browser to inspect element.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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