During the analysis I came to know various ways to secure the PDF files such as Form authentication,storing the PDF files in other secure formats(like .recourse) and while calling the PDF file just save as the file into PDF and rendered using Response.WriteFile method, using session Id with the PDF file name and a few more.
For the stored PDF files or the Crystal reports need to generate and to be stored in a external device for the future purpose
We can use the below methods
1.Create a separate page 'SecurePdf.aspx'. we can use this page for entire application
2.Place a Iframe control
iframe id="fraPdfRender" runat="server" height="800" scrolling="auto" width="100%"
3.If crystal report need to rendered as a PDF file, first convert that into PDF file using the export method of crystal document and use the below code on the required page which the report or the PDF file need to rendered . It will open the 'SecurePdf.aspx' in a separate window (the popup blocker should allow this site, or if it is not required to open in a new window use the normal response.redirect method for opening the page)
string url = reportfilename;
Session["securePdf"] = url;
string script = "window.open('/reports/securePdf/SecurePdf.aspx','new_Win');";
ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", script, true);
Session["securePdf"] = url;
string script = "window.open('/reports/securePdf/SecurePdf.aspx','new_Win');";
ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", script, true);
4.place this code in the code behind file
string url = Session["securePdf_n"].ToString();
HtmlControl frame1 = (HtmlControl)this.FindControl("fraPdfRender");
frame1.Attributes["src"] = url;
string url = Session["securePdf_n"].ToString();
HtmlControl frame1 = (HtmlControl)this.FindControl("fraPdfRender");
frame1.Attributes["src"] = url;
I believe this code is easy to impalement and the url of the PDF file is not shown to the user.I implemented into my application but didn't get the feedback from my client.
If Crystal reports needs to generate for on demand as PDF file:
after analyzed some I used the below method
ReportDocument crReportDocument;
crReportDocument = new cReportName();
crReportDocument = new cReportName();
crReportDocument.ExportToHttpResponse(ExportFormatType.PortableDocFormat,HttpResponse,false);
this will convert the crystal report into PDF automatically and render into the browser without storing in a external disk.
Believe it will helpful for the secure PDF file handling , rendering the Crystal report as PDF file and for opening the report in separate window.
As comments and opinion always expected from you
No comments:
Post a Comment