user191152
user191152

Reputation:

Does ASP.NET MVC search in the Root path for a folder named the same as the Controller?

I might have come across a bug in ASP.NET MVC, but I'm not sure (after searching for an explanation) if I am right here.

ASP.NET MVC weighs heavily on "Convention over Configuration", which is nice, if they stick to it.

I created a controller called "ChatController", and I made a Folder in the Root-path of my project called "Chat", to keep my Chat-related ViewModel in.

Then I created a folder called "Chat" in my "Views" folder, because as we all know, ASP.NET MVC will look in the "Views/[ControllerName]"-folder and "Views/[Shared]"-folder for a matching view.

But every time I tried to hit my View, I got "404". I figured. Hell, maybe I messed something simple up. So I copied from something that worked, and just renamed. Nope.. still 404.

Then I figured.. but.. it couldn't be... NOOO, it couldn't be that I have a folder in the root being called the same as in my Views/ folder? could it ?

I renamed... And Bingo.. my View got hit, and everything worked.

Am I wrong when I say that this is against how ASP.NET MVC is supposed to work. Isn't it supposed to look ONLY in Views/[ControllerName] and Views/Shared for a suitable View?

If I'm wrong, please point to some literature on the subject (if you know any)... This really looks like a bug to me.

Thanks in advance!

Upvotes: 2

Views: 502

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038850

This is more related to how ASP.NET works rather than ASP.NET MVC. When you had Chat folder in your root and you requested /Chat the web server always prefers serving physical folders before the routing engine. So it looked for a file called Default.aspx (or any default document you've setup) in your /Chat folder, it couldn't find one and it blew with 404.

In ASP.NET 4.0 you can relax it :-)

<httpRuntime relaxedUrlToFileSystemMapping="true" />

Upvotes: 1

Related Questions