Please enable JavaScript.
Coggle requires JavaScript to display documents.
.NET MVC FW (Controller Extensibility (Create a custom controller factory.…
.NET MVC FW
- Create a custom controller factory. (Implement the IControllerFactory interface)
- Prioritize namespaces in the default controller
factory (Use the DefaultNamespaces collection)
- Create a custom controller activator (Implement the IControllerActivator interface)
- Create a custom action invoker (Implement the IActionInvoker interface)
- Specify an action name that is different from the
action method name (Use the ActionName attribute)
- Control the selection of action methods (Apply action method selectors)
- Prevent a method from being used as an action (Use the NoAction attribute)
- Create a custom action method selector (Derive from the ActionMethodSelectorAttribute
class)
- Respond to requests for non-existent action
methods
Override the HandleUnknownAction method in the
controlle
10 . Control how controllers use the session feature (Return a value from the SessionStateBehavior
enumeration in the IControllerFactory
implementation or apply the SessionState attribute
to the controller class)
- revent controllers from blocking worker threads
when waiting for input (Create an asynchronous controller)
- Filter (inject extra logic in request processing) Log/Authorize/Cache
- Inject extra logic into request processing (Apply filters to the controller or its action methods)
- Restrict action methods to specific users and groups (Use authorization filters)
- Authenticate requests (Use authentication filters)
- Process errors when executing requests (Use exception filters)
- Inject general-purpose logic into the request handling process (Use action filters)
- Inspect or alter the results generated by action methods (result filter)
- Use filters without attributes (Use the built-in controller method)
- Define filters that apply to all action methods in the application (Define global filters)
- Control the order in which filters are executed (Use the Order parameter). [All Others Reverse ExceptionFilter.]
- Override global and controller filters for an action method (Use an override filter)
- From the class inherited from IController
-
- From the class based on Controller
Use Action Result
-
-
RedirectToRouteResult
Issues an HTTP 301 or 302 redirection to an action
method or specific route entry, generating a URL
according to your routing configuration
-
-
ContentResult
Returns raw textual data to the browser, optionally
setting a content-type header (Content)
FileResult
Transmits binary data (such as a file from disk or a byte
array in memory) directly to the browser. (File)
JsonResult
Serializes a .NET object in JSON format and sends it as
the response. This kind of response is more typically
generated using the Web API feature (JSON)
-
HttpUnauthorizedResult
Sets the response HTTP status code to 401 (meaning
“not authorized”), which causes the active
authentication mechanism (forms authentication or
Windows authentication) to ask the visitor to log in (None)
-
-
-
- Get information about request
- define action method parameters
MVC provide data for parameters by: Request.QueryString, Request.Form, RouteData.Values
-
-
u Extract it from a set of context objects.
u Have the data passed as parameters to your action method.
u Explicitly invoke the framework’s model binding feature.
(base Controller class): Request, Response, Server, RouteData, HttpContext. (Included User and TempData(for current user))
- Tell MVC Framework to render a view
-
- Create Controller: Delivery from IController or Controller class
- Key Features Of Controller Class: Action Method/Action Result/Filters
- Pass data from Controller to View
Untype/WeakType View VS Strongly Type View (@model TypeName)
-
- Redirect Browser (Pattern: Post/Redirect/Get prevent double click)
- Redirect Browser to new URL
-
-
- Redirect to a URL is generated by RouteRoute
-
-
- Redirect to another Action Method
-
- PRESERVING DATA ACROSS A REDIRECTION
-
TempData:- use direct/redirect; - method: Peek(not mark to removed), Keep (not to delete, but 1 time!). For more use: SESSION
- Send Http Status Code to the browser
- Use HttpStatusCodeResult object
HttpNotFound/HttpUnauthorizedResult/(public HttpStatusCodeResult StatusCode() {
return new HttpStatusCodeResult(404, "URL cannot be serviced");
})
- Create Custom View Engine (Implement the IViewEngine and IView interfaces)
- Customize the Razor view engine (Derive from the RazorViewEngine class)
- Define regions of content for use in a layout (Use Razor sections)
- Apply sections in a layout (Use the RenderSection and RenderBody helpers)
- Define reusable fragments of markup (Use partial views)
- Define reusable business logic (Use child actions)
-