I'm having a tricky issue (bear with me as I'm new to MVC) with trying to use a controller (and a route subsequently) with the name PropertiesController.
I believe this is because there is a directory (which I can't really remove) called "Properties" in my solution. Is there a way round this?
The route setup is just one simple route:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Properties", action = "List", id = "" } // Parameter defaults
);
and the error I get in IIS7 when requesting "http://localhost/aptment2/properties/" is:
Surely there is a way round this that I just can't find? Cheers.
IgnoreRoute(RouteCollection, String) Ignores the specified URL route for the given list of available routes. IgnoreRoute(RouteCollection, String, Object) Ignores the specified URL route for the given list of the available routes and a list of constraints.
In MVC, routing is a process of mapping the browser request to the controller action and return response back. Each MVC application has default routing for the default HomeController. We can set custom routing for newly created controller. The RouteConfig.
Endpoint routing is a feature newly introduced in ASP.NET Core that enables you to provide routing information to middleware in the request processing pipeline. Before the introduction of endpoint routing, routing resolution in ASP.NET Core MVC was performed at the end of the request processing pipeline.
Every ASP.NET MVC application must configure (register) at least one route in the RouteConfig class and by default, the ASP.NET MVC Framework provides one default route. But you can configure as many routes as you want.
Since someone else is having the same problem, I'm guessing that you're running into a reserved keyword here (I imagine ClassControllers are out as well).
It's not the first time it's happened either - digging deeper into the internals of the environment, you can't route to Windows' reserved keywords either.
I have a PropertiesController
setup on a MVC 3 application configured to use IIS Express. I don't get the exact error that you do, but it is similar (404.20 no default document) and I'm sure it is for the same reason.
It doesn't cause a problem at all in our production environment since we publish a compiled build of the app and then it doesn't have a Properties folder.
To get around the issue while developing locally I've got all my static content (scripts/css/etc...) in a single directory and I ignore it while also turning on RouteExistingFiles
.
routes.IgnoreRoute("static/{*wildcard}");
routes.RouteExistingFiles = true;
This fixed my issue and now I can browse example.com/properties/ error free.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With