How to store confidential PDF documents (file system vs. SQL) if we only use forms authentication

帅比萌擦擦* 提交于 2019-12-06 16:48:39

You are really dealing with two different issues here: storage system for the documents and security for the documents.

In terms of storage location, you can store them directly in the file system or store them using SQL 2008's FileStream feature.

In terms of securing them, I would go with something similar to what FreudianSlip suggested. Have a page where you pass it the document name (or some other key, such as the ID if storing it in SQL Server), and have that page verify the user's authorization, read the file, and push it back in the response stream.

No matter what, I would recommend updating your web.config to use actual Forms Authentication and authorization so you don't need to explicitly check the cookie each time. It will be handled by the asp.net platform.

You could, instead of making the link a direct link to the pdf document, make it to a script that validates any needed credentials, then if all is good, feeds the file.

http://link.to.pdf/servePDF.asp?docname=mycasedoc.pdf

servePDF.asp validates any sessions/cookies and if all is ok pushes the doc.

something like this.

using System.Net;

string pdfPath = Server.MapPath("~/SomePDFFile.pdf");
WebClient client = new WebClient();
Byte[] buffer = client.DownloadData(pdfPath);
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", buffer.Length.ToString());
Response.BinaryWrite(buffer);

this option would allow you to completely obfuscate the true location of the file.

You can use the Global.asax Application_AuthenticateRequest event and write custom logic based on a static folder (like /assets/) and do your custom validation there.

Likewise, you can also register a HTTP Module and do the same thing. http://support.microsoft.com/kb/307996

You could also implement a HTTP Handeler to accept requests to a given path and then doing some validation and return the file contents like Jeff Turner suggested.

See http://support.microsoft.com/kb/308001

I would suggest keeping the PDFs in their separate directory. Then build an additional web.config file in that same directory to specify form authentication access. For example:

<system.web>
    <authorization>
        <allow users="Foo"/>
        <deny users="*"/>
    </authorization>
</system.web>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!