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
- In the Azure Portal, open the blade for the web app.
- Click on Application settings under SETTINGS menu.
- Scroll to Virtual applications and directories.
- Add a Virtual Directory
/public
, then enter Physical path site\wwwroot\uploads\images
.
- Click Save.
Here is the picture:
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.