How do I store files outside of C# ASP.NET application root folder in IIS.

Posted on 2013-11-08
Medium Priority
Last Modified: 2013-11-16
"../" style parent paths do not work
"~/" tildas  do not work as they only go to the app root also

It is important to not this WebApp is stored in a same named subfolder shown as bold.  
It is an MVC ASP.NET C# 4.0 database editing APP.
eg c:\inetpub\wwwroot\projectname\projectname

In the Root Folder I have a standard ASP.NET web application in Italics.
I need some advice or code on how to escape the application in the subfolder to store files in the true root folder.

My IIS version is 8 on an x64 machine.

Does this request have anything to do with "Double Escaping" that can be overridden in the request filtering? or is that unrelated.
I am interested in a web.config based solution if at all possible, in an attempt to overcome ever changing IIS security changes.
Question by:XGIS
  • 3
  • 2
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39635368
The only way I know to accomplish this is to make a symbolic link to the parent folder from within the child folder. Then it appears as though the parent is a child of the child, but on the physical file system it is not. You can use the mklink utility for this.

Accepted Solution

XGIS earned 0 total points
ID: 39639788
To overcome the issue of uploading ABOVE the APPLICATION ROOT Folder is very simple if you use Virtual Directories in IIS.
This example is created based on the ANM10 Generated Website being Nested in another website.
The reason for this is it gives me somewhere to put folders and files so I do not risk accidentally generating over my folders and files.
It also helps me to maintain a single folder in WWWROOT for all Website related tasks.
It is also a good place to store sensitive files such as the AGX which should NOT be located in the published website folder.

Related Posts:
Custom Image Upload Folders - Row_Inserting Event - viewtopic.php?f=45&t=33634
Increase Image - File Uploads to 100Mb - viewtopic.php?f=45&t=33638

The Goals:
1. Store Files in Folders Above the Application Root Folder; e.g. C:\inetpub\wwwroot\MainWebsite\YourCustomVDUploadFolder\
2. Manage Files elsewhere using a Virtual Directory in IIS here; e.g. C:\inetpub\wwwroot\MainWebsite\ANM10WebsiteAppRoot\
3. Enable complete site regeneration without risk of losing existing folder based data.
4. Cleaner, safer and faster delivery of presentation application eg ASP.NET
5. Static safe folder for server scheduled backups of data eg using BAT files etc

All code will be directed at the Virtual directory but all files will actually live in the physical folder above the application root.
There is need to even create the folder. If you do and you always regenerate using "Clear All" you would have to manually create it each time or code it to autogenerate.

1. Windows Explorer: Create this folder; e.g. C:\inetpub\wwwroot\MainWebsite\YourCustomVDUploadFolder"
2. IIS: Click on this folder e.g. C:\inetpub\wwwroot\MainWebsite\ANM10WebsiteAppRoot\
3. Right click to create the Virtual Directory folder e.g. "YourCustomVDUploadFolder" which simply points to the physical folder that in this case is one folder above the Application Root.

This is NOT limited to this structure or location, but the example was based only on my immediate needs.
Maybe you have an existing or separate website where the files need to be made available e.g D or E etc.
This is NOT limited to custom uploads referred to in the posts above. The same should be possible for standard ANM10 file upload to folder based projects.
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39640014
I try to minimise 3rd party dependencies and utilise existing infrastructure to avert breakdowns
mklink is a utility provided by Microsoft, and it comes already installed in Windows Server, so I wouldn't consider it a "3rd party" solution. But if you've got a working solution, then that is what counts  = )

Author Comment

ID: 39640081
Hello kaufmed.. apologies for my bad choice of words... it should have been something like code dependencies.  Again thankyou for your time and i welcome your suggestions in the future.

Author Closing Comment

ID: 39653041
Hello Kaufmed.. thankyou for your time..while your suggestion may have been suitable in some programming scenarios it was difficult to integrate as my IDE is restricted in what it can and cannot use. Similarly I try to minimise 3rd party dependencies and utilise existing infrastructure to avert breakdowns.  IIS Virtual directories were all that was required to overcome application limitations and IIS security issues.

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
This article describes and provides a custom-made tool I wrote to give businesses a means of identifying commercial music content, without having to expend too much effort. Business recordings are easily identified from possibly illegal music files …
From store locators to asset tracking and route optimization, learn how leading companies are using Google Maps APIs throughout the customer journey to increase checkout conversions, boost user engagement, and optimize order fulfillment. Powered …
In the video, one can understand the process of resizing images in single or bulk. Kernel Bulk Image Resizer is an easy to use tool for resizing large number of images. One can add and resize multiple images with this tool in single go. The video sh…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question