Hi fabio.medeiros,
Thank you for posting the clear demo. However, I have to tell you that this issue is by design and doesn’t have any workaround.
When we input the path instead of the real file, such as http://localhost/VirtualPath, IIS will try to find if there is a default page defined in IIS metabase. If such file doesn’t exist, IIS will try to list the files in the required folder, if the folder doesn’t exist at all, “HTTP 404 - File not found” error will be raised.
For example, when you try to browse http://localhost/VirtualPath/test/one/, IIS will search the metabase to check if there has any default page. If the file exists (such as Default.aspx), IIS will route the request to ASP.NET worker process, then ASP.NET will know the request and handle it as expected. However, if the file doesn’t exist, IIS will not route the request to ASP.NET worker process and directly response to client with error message, so that ASP.NET totally doesn’t know the request.
To clarify this issue, please do a test with following steps in IIS manager:
1. Right click the “VirtualPath” node and then select “Properties”.
2. Go to “Documents” tab, uncheck the “Enable Default Document” option, or delete the “Default.aspx” item.
3. Try to browse: http://localhost/VirtualPath/test/one/, it will give the “HTTP 403” error (“Directory browsing” option unchecked) or list the contents of the folder.
Why does http://localhost/VirtualPath/test/two/Default.aspx work well? It’s is because in IIS mappings, the file which extension is aspx will be routed to “c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll”, so this request will be route to ASP.NET worker process directly, then it will be redirect to the correct page by your clsVirtualFile class.