I am developing a site on which there are several files that I want to download only if users have sufficient access to my conditions.
In principle, I have a page on which there is a download link, but the download link will be displayed and activated only if the user has the correct roles and they 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 went to www.mysite.com/downloads/myfile.pdf - I don’t want them to be able to get the file, although I want to be able to allow them to download it as soon as they are logged in, and I verified that they are following my own rules and regulations.
I was going to do it like this, but I believe that with deactivated permissions I cannot do it.
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 goals? Hope I have explained enough.
thank
source
share