2

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?

Sheiky
  • 41
  • 1
  • 7

3 Answers3

2

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= so the file will be load on the inside of the iframe. Of course you can find many other examples.

Community
  • 1
  • 1
Aristos
  • 66,005
  • 16
  • 114
  • 150
1

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

Pritam
  • 685
  • 1
  • 14
  • 29
0

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.

Amit
  • 882
  • 6
  • 13