locked
How to Prevent direct access to Image, pdf files in asp.net. RRS feed

All replies

  • User-1377768212 posted

    Hi,

    You can use "iTextSharp" free library for password protection security in PDF file using Asp.Net & C# .

    Reference :

    https://www.aspsnippets.com/Articles/Create-Password-Protected-Secured-PDF-using-iTextSharp-in-ASPNet.aspx

    Tuesday, December 26, 2017 10:05 AM
  • User-1838255255 posted

    Hi SSK_Nani,

    Through your needs, about how to prevent the files be accessed, please check the following sample code:

    <location path="image path">
        <system.web>
          <authorization>
            <allow roles="Admin"/>  
            <deny users="*"/> 
          </authorization>
        </system.web>
      </location> 

    Best Regards,

    Eric Du 

    Wednesday, December 27, 2017 6:49 AM
  • User1738843376 posted

    There are a number of different approaches to this, depending on how you want to use the images.

    1. You can convert them to byte and store them in the database. This will ensure only through a DB access can you retrieve the image, and the same DB access requires a user and pass;
    2. You can store them on a particular folder, use Location on the web.config to restrict access, and use formsAuthentication to only allow authenticated users to access the files within the folder;
    3. you can stream the images to the browser, and only allow the streamer snippet to access the images in the first place if the user is authenticated, ence never showing the full path to the image, preventing users from accessing it outside the constraints of the website/app;
    Thursday, December 28, 2017 5:35 PM