0

My folder structure is like this.

application
system
public
uploads > images
index.php
----------

I want to restrict access the images in uploads folder from non-users by typing path in URL (Ex - www.exapmple.com/uploads/images/new.png ). My hosting is Azure, I think it dosen't support .htaccess also.

1

2 Answers 2

0

Azure uses IIS to host your web app. So to achieve your requirement, you can first add IIS configuration file named web.config under the /wwwroot folder, then add the following element into <system.webServer>.

<security>
  <requestFiltering>
    <hiddenSegments>
      <add segment="uploads"/>
    </hiddenSegments>
  </requestFiltering>
</security>

Finally the web.config will be something that looks like:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.webServer>

    <security>
      <requestFiltering>
        <hiddenSegments>
          <add segment="uploads" />
        </hiddenSegments>
      </requestFiltering>
    </security>

  </system.webServer>
</configuration>

This will prevent all users from direct access to /uploads folder and its content.


Edit:

You can use Virtual Directory to show images in upload folder to public.

Step by Step

  1. In the Azure Portal, open the blade for the web app.
  2. Click on Application settings under SETTINGS menu.
  3. Scroll to Virtual applications and directories.
  4. Add a Virtual Directory /public, then enter Physical path site\wwwroot\uploads\images.
  5. Click Save.

Here is the picture:

enter image description here

Now you can type the path in URL www.exapmple.com/public/new.png to access the image which actually locates under site\wwwroot\uploads\images folder.

1
  • Thank you for your reply Aaron. But my problem is,I want to show images in upload folder to public. (users and non users) Any of user not able to direct access the image from URL. With your solution I cant show image to public. Is there any possible way to block direct access the images in upload folder by URL instead of system retrieve the image?? I think you can understand my situation! Commented Feb 13, 2017 at 17:13
0

I added below code to uploads folder as web.config (because of .htaccess files are not working in Azure hosting). After that I converted all images to base64 encoding. For the image views I used base64 decoding. From this solution I solved my problem easily.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.