0

I have a sub folder named "images". I want to load all the file names from "images" folder into my html page using jQuery/JavaScript on a secure web site.

How can I do this?

I know how to do this for an unsecured site: How to load all the images from one of my folder into my web page, using Jquery/Javascript

EDITED: It's an https page. I can get the contents of a folder in an http page, but I get an '403 - Forbidden: Access is denied.' error for the folder in an https page. I have access to webserver. I use ASP.NET and tried to set permissions in web.config on the folder for all users. I want to get the list from the client side. The client script is executed through the same-origin policy. I use an ASP.NET web page (but I want to get the files through JavaScript/jQuery). I might use web services.

  • what exactly does *"secure page mean"*? Why is it any different than loading images in any other page – charlietfl Nov 25 '17 at 18:39
  • 1
    I guess it means he cant list the filenames from folder, which a basic security rule. You need to give a little bit more of details, like do you have access to the webserver? Which technologies / framework / language do you use on the server side. Theres a PHP way here https://stackoverflow.com/a/22420248/117314 . Or here for inspiration https://github.com/lthr/show-all-images-in-a-folder-with-php – Loic El Thesea Nov 25 '17 at 18:48

1 Answers1

0

Thanks for the details. Im sorry I cant set up an ASP.Net website right now, but I still have a few questions.

Is the client script executed through the same-origin policy or do you need to enable CORS / JSONP ? https://learn.microsoft.com/en-us/aspnet/web-api/overview/security/enabling-cross-origin-requests-in-web-api

Do you use ASP.Net WebPage, MVC, WebApi, which version or the new ASP.Net Core version?

My recommendation is to build a webservice/API that reads the folder and delivers the list of files:

  • you can deliver any format you want like a nice JSON, works well with jQuery
  • you don't need to add/manipulate the web.config which is always better
  • you will be able to cache the response and avoiding to much disc access. Therefore you need to watch the folder for changes and update the cache
  • if you want to move/split the folder, moving to a db, anything you might need later, its still gonna work: the url will remain the same

With WebApi this might helps: https://stackoverflow.com/a/25986573/117314

Loic El Thesea
  • 704
  • 7
  • 17