c# - Why does empty controllerName property work when the default action is empty? -


i reading on urls , routes chapter in pro asp.net mvc 3 , tried see happens when object defaults contain empty values. route have @ moment.

routes.maproute("myroute", "{controller}/{action}",      new { controller="home", action="index" }); 

following observations made possible combinations of values of object defaults. (in each case, urls in bold not accessible.)

case 1

new { controller="home", action="index" }); 
  1. http://mywebapp.net/
  2. http://mywebapp.net/home/
  3. http://mywebapp.net/home/index/

case 2

new { controller="home", action="" }); 
  1. http://mywebapp.net/
    error: routedata must contain item named 'action' non-empty string value.
  2. http://mywebapp.net/home/
    error: routedata must contain item named 'action' non-empty string value.
  3. http://mywebapp.net/home/index/

the above error 2nd url because routing system couldn't find default action name.

case 3

new { controller="", action="" }); 
  1. http://mywebapp.net/
    error: value cannot null or empty. parameter name: controllername
  2. http://mywebapp.net/home/
    error: routedata must contain item named 'action' non-empty string value.
  3. http://mywebapp.net/home/index/

the above error 1st , 2nd urls because routing system couldn't find default controller , action names respectively.

case 4

new { controller="", action="index" }); 
  1. http://mywebapp.net/
    error: value cannot null or empty. parameter name: controllername
  2. http://mywebapp.net/home/ (how , why accessible?)
  3. http://mywebapp.net/home/index/

when both controller , action properties empty in case 3, received errors expected. in case 4, how 2nd url http://mywebapp.net/home/ accessible when have empty value controller property?

is simple 2nd url being accessible because homecontroller defined , routing system found convention or there explanation behavior? can modified let 2nd url inaccessible or violate convention-over-configuration principle?

home , index not hardcoded conventions, unless specify them defaults runtime won't attempt find them.

case 2.1 not work because url did not contain value action parameter, , there's no action default.

case 4.1 not work because url did not contain value controller parameter, , there's no controller default.

i recommend this post if want more details how routing works.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -