Page controller mode
In the page controller mode, a central class named basecontroller is used to implement all the public behaviors required, so as to process HTTP requests, update models, and forward requests to appropriate views. Basecontroller provides common functions including session management, security, and data retrieval from query strings or hidden fields.
For Web Applications Program For each link in, you must create an independent pagecontroller class, which must be inherited from the basecontroller class. These independent pagecontrollers are responsible for implementing any behavior specific to webpages and directly using the core functions that have been implemented by basecontroller.
In many cases, your applications can be divided into a series of common web page types, which share common logic. For example, you may have a series of data input pages or grid view pages that share the same logic. In this case, it is best to implement a dataentrycontroller or a gridviewcontroller and require them to inherit from the basecontroller class. Based on these derived classes, you can implement your own pagecontroller and use existing public methods. However, it should be noted that the inheritance hierarchy cannot be too complex, otherwise the application logic will become difficult to maintain. To minimize the length of the inheritance chain, you can create a series of "helper classes" that contain a series of common Code Can be called at any inheritance level.
To implement the page controller mode, you can inherit a basecontroller class from system. Web. UI. Page and then implement common application functions. For example, basecontroller can provide headers, footers, and user-specific information (such as logon names and departments) to achieve consistent appearance and feeling. Then, you can inherit from the basecontroller class and implement the unique logic of the webpage by the inherited class (put in the hidden code file) to create every page required by the application.
This mode is especially suitable for medium-complexity applications that have fixed navigation paths. On the contrary, if you need dynamic navigation, you need to use the front controller mode.
Front Controller Mode
If Cooperative Processing is required between multiple webpages, the efficiency of the page controller mode is greatly reduced because it requires that an object be re-implemented for each logical webpage.
In this case, the front controller mode is more effective because it uses a controller to receive all requests and then directs requests through a hierarchy of processing programs and command classes. The handler obtains parameters from the HTTP request, selects the correct command, and executes it. After each command object executes a specified operation, it determines which view to use to correctly present the webpage. By implementing the Front Controller, you can get more centralized application control, because all webpage requests are handled by a separate controller rather than by different page controllers. But this is not without a cost: If the processing program performs some high-end processing, such as database search, it may cause the whole application to run slowly. Therefore, the handler should be as efficient as possible and use external resources only when absolutely necessary.
You should also consider caching any external resources to improve the processing performance. To implement the frontcontroller class, you need to create a handler and a commandfactory to determine the commands to be executed in response to a request. ASP. NET provides the ihttphandler interface, which allows developers to create custom interfaces required to provide services for incoming HTTP requests. To implement handler, You need to inherit from system. Web. ihttphandler and add the corresponding logic to instantiate and call appropriate commands from commandfactory. Commandfactory defines a command set and the logic used to determine the command to be executed. When commandfactory is called, an appropriate command object is returned, and handler can call the execute method of the object. In this mode, you can extend the commandfactory logic and create additional commands to handle different actual situations, so as to create a more reliable navigation mechanism and implement them in a centralized manner. The. NET constructor should try to use the structured mode. With the built-in ASP. NET features, you can easily implement the page controller and Front Controller modes. Use them to obtain highly reusable and Scalable Application designs.
For more information about these and other structured modes and the Implementation Details of ASP. NET, visit Microsoft. NET architecture center.