views:

60

answers:

0

I have a couple of questions about controllers and routes in asp.net MVC

1) By default Index() action from Home Controller will executing if i type "http://mymvcsite" or "http://mymvcsite/Home" or "http://mymvcsite/Home/Index". What is the better way to configure routes to allow only "http://mymvcsite" or "http://mymvcsite/home".

e.g if somebody type "http://mymvcsite" or "http://mymvcsite/Home/Index" he will be redirected to "http://mymvcsite/Home" or another way, the similar logic, if somebody type "http://mymvcsite/home" or "http://mymvcsite/Home/Index" he will be redirected to "http://mymvcsite"

2)If i have controller "http://mymvcsite/controller" but if somebody type some rubbish (not existed path) e.g "http://mymvcsite/controller/skldfjslsdfsdf?http=2" in that case i want to redirect to "http://mymvcsite/controller", but if somebody type something like that "http://mymvcsite/notexistedcontroller/blablabla" i want to redirect to default controller. Another words if controller or controller/action in url exists i want to redirect to this controller if not exist i want to redirect to default controller.

3) If somebody come to this controller "http://mymvcsite/controller" or "http://mymvcsite/controller/action" and than he type in url some rubbish "http://mymvcsite/controller/rubbish" or "http://mymvcsite/controller/action/rubbish" and than after pressing enter i want he still stand on the same place and nothing bad happens.

4) May be it is useful to do such logic to process all that cases (question 2 - 3) may be if wrong url it is better practice to redirect to error page with text that such url not exists?

happy to hear any opinions.