简体   繁体   中英

ASP.Net MVC Allows Explicit Routing to Specific File Having Dot in the Folder Name

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.

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:

在此处输入图片说明

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

在此处输入图片说明

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

在此处输入图片说明

And now we can conveniently browse the folder:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM