Question

I'm running into a bizarre problem trying to establish a non-conventional folder structure for my MVC project:

\Franchises\Compliance\FeesPaid\FeesPaidController
\Franchises\Compliance\FeesPaid\Views\..
\Franchises\Compliance\FeesPaid\ViewModels\..

My plan is to have 1 controller in each sub folder, along with associated views/viewmodels folders. I prefer not to have a /Controllers/ folder which will only ever contain a single class.

For testing purposes I am manually routing like this:

routes.MapRoute("whocares", "Franchises/Compliance/{controller}/{action}/{id}",
            new { controller = "FeesPaid", 
                  action = "Index", 
                  id = UrlParameter.Optional });

I run into mysterious behavior. These URLs route correctly:

http://localhost:12345/Franchises/Compliance/FeesPaid/Index
http://localhost:12345/Franchises/Compliance/FeesPaid/Index/123

But this URL fails with "The Web server is configured to not list the contents of this directory" error:

http://localhost:12345/Franchises/Compliance/FeesPaid

I found this only occurs when the Controller name matches the folder name (minus "*Controller"). So fudging the controller name to something else makes it work:

\Franchises\Compliance\FeesPaid\FeesPaidXController

http://localhost:12345/Franchises/Compliance/FeesPaidX
http://localhost:12345/Franchises/Compliance/FeesPaidX/Index
http://localhost:12345/Franchises/Compliance/FeesPaidX/Index/123

Why would a controller & folder having matching names cause it to fail when the URL relies on default action & id?

edit

On investigation it turns out that IIS is routing the request to DirectoryListingModule instead of MVC, so it's not even reaching MVC routing.

I have tried the following to no avail:

<system.webServer>
  <modules runAllManagedModulesForAllRequests="true"  >  <--- attribute added
    <remove name="FormsAuthenticationModule"/>
  </modules>
</system.webServer>

<system.webServer>
  <modules runAllManagedModulesForAllRequests="true"  >
    <remove name="FormsAuthenticationModule"/>
    <remove name="DirectoryListingModule"/>    <--- Fails to start web app with "lock violation"
  </modules>
</system.webServer>

How can I force IIS to route these requests to MVC instead of DirectoryListingModule? Preferably without IIS configuration changes I may not have control over in production.

Was it helpful?

Solution

Thanks for everyone's comments.

Further investigation has lead me to post another question here:

How to disable or reprioritize IIS DirectoryListingModule under MVC module?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top