Custom Folder Structure in ASP.NET MVC 5 -
i'm trying determine if possible (or practical) implement uncle bob's screaming architecture in asp.net mvc 5 rather using default folder structure.
here's link description of screaming architecture: http://blog.8thlight.com/uncle-bob/2011/09/30/screaming-architecture.html
a hypothetical folder structure this:
root
- customers
- controllers
- customercontroller.cs
- models
- customer.cs
- views
- index.cshtml
- details.cshtml
- update.cshtml
- controllers
- employees
- controllers
- employeescontroller.cs
- models
- employee.cs
- views
- index.cshtml
- details.cshtml
- update.cshtml
- controllers
- shared
- views
- _layout.cshtml
- error.cshtml
- views
- _viewstart.cshtml
- web.config
the corresponding url routes this:
- http://www.example.com/customers/ => customer index
- http://www.example.com/customers/details/1 => customer details
- http://www.example.com/customers/update/1 => customer update
- http://www.example.com/employees/ => employee index
- http://www.example.com/employees/details/1 => employee details
- http://www.example.com/employees/update/1 => employee update
i've created custom razorviewengine , added appropriate view location formats (e.g. "~/{1}/views/{0}.cshtml") , partial view location formats (e.g. "~/shared/views/{0}.cshtml"). i've moved shared _viewstart.cshtml root , merged views/shared folder's web.config root-level web.config avoid having duplicate these 2 files in of view folders.
everything works great, however, if try navigating index page (e.g. http://www.example.com/employees/) 403.14 error (forbidden). other routes (including http://www.example.com/employees/index) work fine.
my guess iis explicitly blocking route controller's index method because url coincides folder in filesystem , directory browsing disabled default. if enable directory browsing, however, takes me actual directory listing rather routing controller's index method.
i can move customers , employees folders subfolder (i.e. move them out of root) , works fine, i'd try keep these folders @ top level (per screaming architecture guidelines).
does have solution issue?
please note mvc areas not solution i'm looking not allow folder structure described above (i.e. top-level folders named after high-level use cases , views contained directly within views folder rather in subfolder).
i'm betting right iis then. if have 2 paths mapped same resource, physical path checked first on iis side.
i digging around routes configuration , found property routeexistingfiles on routecollection
, think work.
i set value true
, tested locally empty folder in project, route redirecting home/index
, , navigating localhost:xxx/myfolder
. worked correctly.
so should need set property true choose asp.net routes first instead of physical routes.
Comments
Post a Comment