Q: How I can prevent a public method in MVC controller from being an Action Method?
A: We can decorate the public method with “NonActionAttribute”. This will prevent public methods to be called as Action methods which is the default behavior of MVC.
Q: Is given below is a valid Route Definition?
A: No, its not because there is no literal value or delimiter between the placeholders. Therefore, routing cannot determine where to separate the value for the controller placeholder from the value for the action placeholder. Valid definition will be
Q: How do you handle variable number of parameters in a route definition?
A: You can define different number of parameters in a route using “Catch-All” parameters. Example is shown below:
* is referred to as catch-all parameter which can catch all parameters.
Q: What are different scenario where Routing Mechanism will not work?
A: There are generally 2 scenario where routing will be ineffective:
- If there is some physical file is there at the given url pattern like an Image, CSS or some other content file. But we can override this default behavior by setting RouteExistingFiles property of the RouteCollection object to true
- If we explicitly disable some routes for a given url pattern. In this case url with particular patterns will be ignored. This can be done by using RouteCollection.Ignore() method.
Q: What are the different levels at which you can apply Filters?
A: Filters can be applied at 3 different levels:
- On Action Method
- On Individual Controller
- On Entire Application
Q: What are the various types of Filters and which filter executes First and Last?
A: There are 4 different types of filters:
- Authorization Filters
- Action Filters
- Result Filters
- Exception Filters
Authorization Filter executes first while Exception filter executes lasts.