Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC Routing with a controller named "PropertiesController" [closed]

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:

alt text

Surely there is a way round this that I just can't find? Cheers.

like image 230
Kieran Benton Avatar asked Jul 01 '09 18:07

Kieran Benton


People also ask

What is IgnoreRoute route MVC?

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.

How routing is working in MVC?

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.

What is MVC endpoint routing?

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.

How many routes are there in MVC?

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.


2 Answers

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.

like image 91
48klocs Avatar answered Oct 06 '22 01:10

48klocs


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.

like image 38
Aaron Wagner Avatar answered Oct 06 '22 00:10

Aaron Wagner