ASP. NET endpoints des the following types for MVC development:
All controller classes must be suffixed with "Controller" and inherit from the "Controller" base class.
MVC framework (MVC2) considers all public methods to be action methods. Therefore, if your controller class contains a public method that is not an action method, you must mark it with the NonActionAttribute feature.
Action method parameters
By default, parameters of the action method are retrieved from the requested dataset. A data set includes data, query string, and name/value pairs in cookies.
The controller class locates the action method and determines the parameters used for the method based on the RouteData instance. If the parameter value cannot be parsed, the NULL value is passed for the reference type or NULL type. Otherwise, an exception is thrown.
There are several ways to obtain the URL parameter value in the action Method of the control class. The Controller base class exposes the Request and Response objects used in the action method. The two objects share the same meaning as HttpRequest and HttpResponse. One important difference is that the Request and Response objects in the Controller class are based on the System. Web. IHttpRequest and System. Web. IHttpResponse interfaces. This interface makes it easy for them to create a mock object, making it easy to create unit tests for the Controller class.
Process undefined Action name
The Controller base class calls the HandleUnknowAction method to process an unknown action method name. By default, the Controller base class returns an HTTP 404 status code.
You can set the default handler for the action referenced in the URL but the action method does not actually exist. The following example shows how to override the HandleUnknowAction method and redirect it to a "serch" Page:
Public void override HandleUnknownError (string action ){
// Redirect to a search page where the unknown action is
// The search query. Determine when to show the search page
// Based on the result of calling a ShouldShowSearch () method.
If (ShouldShowSearch (action) = true)
{
RedirectToAction ("search", action );
Return;
}
Base. HandleUnknownError (action );
}