I’m developing a site that has a few files on it that I only want to be downloadable if the users have sufficient access on my terms.
Basically, I have a page that has a download link on, but the download link will only be displayed and activated if the user has the correct roles and are associated with the correct properties in my database.
The problem I am facing is that I don’t want users to be able to access the file directly, for example if they go to http://www.mysite.com/downloads/myfile.pdf – I don’t want them to be able to get hold of the file although I do want to be able to allow them to download it once they have logged in and I have checked that they fulfil my custom rules and regulations.
I was going to do it like so, but I believe with the permissions deactivated I won’t be able to do so.
System.IO.FileInfo file = new System.IO.FileInfo(path);
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
Response.AddHeader("Content-Length", file.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(file.FullName);
Response.End();
Is it possible to achieve my aims? Hopefully I’ve explained myself sufficiently.
Thanks
I am sure you at the correct way.
Here is a simple example:
—- EDIT —-
There are others good samples:
http://www.dotnetscraps.com/dotnetscraps/post/4-ways-to-send-a-PDF-file-to-the-IE-Client-in-ASPNET-20.aspx