views:

157

answers:

2

I know it's not perhaps in the true spirit of MVC, but I just want to have a single global controller that always gets called no matter what the url looks like. For example, it could be:

http://myserver.com/anything/at/all/here.fun?happy=yes&sad=no#yippie

...and I want that to be passed to my single controller. I intend to obtain the path programmatically and handle it myself--so in other words, I don't really want any routing at all.

I've opened up the global.asax file and found where routes are registered, but I just don't know what to put for the 'url' parameter in MapRoute:

routes.MapRoute( "Global", "", new { controller = "Global", action = "Index" } );

This (with the blank 'url') works fine for the default path of '/', but if I change it to anything I get a file not found, when I want it to handle any url. I also tried "*", etc. but that didn't work.

I couldn't find any definitive reference to the format that the url parameter takes.

A: 

You have not removed the default have you? You need to keep that one. Maybe try:

routes.MapRoute("Global", "/", new { controller = "Global", action = "Index" });
Tacoman667
No luck, url routes can't start with a slash.
chaiguy
+2  A: 

How about:

routes.MapRoute("Global", "{*url}", new { controller = "Global", action = "Index" } );

from this question

veggerby
That did it, though I don't understand why. Reading up on those 404 pages now... thanks. :)
chaiguy