7

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.

Spooky
  • 2,966
  • 8
  • 27
  • 41
Kieran Benton
  • 8,739
  • 12
  • 53
  • 77
  • Are you trying to browse to that view directly or are you going through the default.aspx page first (such as with an F5 or Ctrl+F5)? Just curious if the route registration is getting bypassed which happens f you have that view set as the start page instead of default.aspx. – nkirkes Jul 01 '09 at 19:00
  • just burned 2 hours trying to debug this, have to remember to his SO first next time – mxmissile Jun 07 '12 at 19:34
  • What's even more messed up is the url `properties/index' works. – mxmissile Jun 07 '12 at 19:37

4 Answers4

5

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.

Community
  • 1
  • 1
48klocs
  • 6,073
  • 3
  • 27
  • 34
4

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.

Aaron Wagner
  • 5,739
  • 1
  • 31
  • 38
2

Running a quick test, I get the same behavior. Is it a viable option to use something other than Properties?

nkirkes
  • 2,635
  • 2
  • 21
  • 36
  • I'd prefer not to if at all possible, after all the idea of MVC is that you have complete control and your URL naming scheme is to be as clean as possible! – Kieran Benton Jul 01 '09 at 19:24
  • Well, sort of. That's the idea behind routing, not necessarily just MVC, but regardless, MVC reles on certain conventions and that includes not using reserved words or names of other resources. I would suggest either looking into locking down that route definition further (I'll add an edit with a suggestion) or coming up with a different name for your controller. – nkirkes Jul 01 '09 at 20:37
  • I tried locking down the route a bit further and get the same result. You might be SOL on this but I'll be curious to see if there's a way around it. – nkirkes Jul 01 '09 at 20:41
  • Looks like you're right - oh well, will have to get my thesaurus out! – Kieran Benton Jul 01 '09 at 22:03
  • FWIW, we have a controller called PropertyController that works just fine in one of our projects. But we have a convention of using singular names for controllers (as opposed to plural such as 'Properties'). – nkirkes Jul 01 '09 at 22:43
0

I don't know if it's an option for you, but you could try to disable routing to existing files.

routes.RouteExistingFiles = false;
chris166
  • 4,769
  • 4
  • 24
  • 25