1

I have an ASP.Net MVC application run on IIS. Is it possible to let the client to directly access certain file in the folder without going through normal (Controller-Action-View) process?

Say, I have the domain name: www.example.com and the file path is ~/.Sample/SubFolder/Filename (note the dot '.' before Sample) relative to www.example.com

Now, without the dot '.', you can create a Controller named Sample and an Action named SubFolder which takes argument Filename and returns the SubFolder View in the Views folder. But this folder is having a dot.

So, I want the application to directly show the Filename content by writing

www.example.com/.Sample/SubFolder/Filename

When I already put the file Filename in the .Sample/SubFolder folder relative to www.example.com and tried accessing it by writing www.example.com/Sample/Filename, the following error is shown:

Server Error

404 - File or directory not found.

The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.

Any idea? A solution using IIS is acceptable.

Ian
  • 30,182
  • 19
  • 69
  • 107
  • You can create a controller method in the `SampleController` and then create a specific route for it that omits the action name, so `/Sample/someFileName` routes to `publicActionResult XXX(string fileName)` –  Feb 24 '17 at 04:29
  • @StephenMuecke that is what I will normally do... But the `Sample` is not really `Sample` it is in fact having a dot in front: `.Sample` -> this cannot be done by normal controller method, no? – Ian Feb 24 '17 at 04:31
  • Refer [this answer](http://stackoverflow.com/questions/11728846/dots-in-url-causes-404-with-asp-net-mvc-and-iis) for info on handling the `dot`, but I don't understand what your mean by `/.Sample/Filename` (where does the dot come from? and is `.Sample` the folder name? –  Feb 24 '17 at 04:36
  • @StephenMuecke yes, `.Sample` is a folder name directly under the root directory of the MVC application – Ian Feb 24 '17 at 04:37
  • In a typical (traditional?) web page, you can put a folder under the root folder having `.` and when people want to open a file under it, they can simply do `www.root.com/.Sample/somefileinthefolder` (note that the dot is in the **folder** name) -> basically I want to do this for a specific file in `ASP.Net MVC` application – Ian Feb 24 '17 at 04:39
  • refer http://www.hanselman.com/blog/BackToBasicsDynamicImageGenerationASPNETControllersRoutingIHttpHandlersAndRunAllManagedModulesForAllRequests.aspx – Chandan Kumar Feb 24 '17 at 05:07

1 Answers1

-1

This problem can be solved in the IIS by choosing the specific folder we want to allow Directory Browsing on.

By default IIS would disable the Directory Browsing feature on all folders. To enable the directory browsing for specific folder, select the folder in the IIS Connections -> Server Name -> Web site name -> Folder name as shown below:

enter image description here

In the Feature View of the specified folder, select the IIS -> Directory Browsing feature:

enter image description here

Then you simply need to enable the feature for the specific folder:

enter image description here

And now we can conveniently browse the folder:

enter image description here

Ian
  • 30,182
  • 19
  • 69
  • 107