Website on IIS Errors When Listing Directories

384 Views Asked by At

I have a VPS (Cloud Server) and I have Visual Studio, IIS, SQL... all those nice things installed. I am also sometimes doing development on this VPS.

This website is basically a simple file manager. When it loads, it lists files and folders that resides in the App_Data folder. This said, I am using the App_Data as my "root/home/topmost-directory" for the file manager.

The reason I am putting them in the App_Data folder is because I don't want users to just go like this: www.mywebsite.com/ROOT/[gets a list of files]. Instead, if they try to go: www.mywebsite.com/App_Data/[tries to get list], IIS will block them with a nice error (because IIS blocks access to that folder).

So, the website accesses the structure in the App_Data folder via code behind. This is how the website navigates. It can download, upload, move files around, rename... delete... everything right to/inside the App_Data folder.

The only problem is, this only works when I run the website in Visual Studio and run my tests, testing the website, debugging, etc. The moment I publish (via File System in Visual Studio) the website to the directory: "C:/inetpub/Sites/[WebsiteFolder]", and navigates to the website's URL, the website does not work any more. It loads, but it does not get the file structure in the App_Data folder any more, it cannot create new folders, cannot rename them...

This website works fine when I upload it via FTP to another webs space that is hosted somewhere else at another hosting company (which is shared hosting).

So I guess (my best guess) the IIS on my VPS does not allow this kind of access. And I have been trying to find settings on IIS somewhere that would/could allow this.

I have enabled directory browsing, but that's probably the only thing I can think of other than making sure the directory is accessible (readable/writable).

Do you perhaps know what else I can try?

1

There are 1 best solutions below

0
On BEST ANSWER

Ohkay, so this was a very silly mistake - but that's how we learn!

The App_Data folder did not have any other files or folders inside of it. And as we know, ASP.NET does not publish empty directories. This means those empty folders never existed once I published the website.

There are 3 ways to fix this that I know of at the moment:

  1. If your solution has a publish profile (so that you can publish the site), you can right click the empty folder in Visual Studio, and say Publish [FolderName] eg: enter image description here
  2. You can just create an empty file in that directory, and publish your whole website again. Because the folder is not empty any more, it publishes with the rest of the website.
  3. Just manually create the folder on your hosting space.

Thanx for everyone's input! Greatly appreciated!