Asp.net MVC plug-in Application Framework

Source: Internet
Author: User

Over the past few years, I have made many website systems and have been insisting on using asp.net mvc to build websites. Every time I start from scratch, I am a little annoyed about Layout, CSS, and permission management, the Code has been well organized over the past few years and is ready to build a framework.

I. Objectives

0) target fields: management applications with relatively standardized website background management systems and MIS structures;

A) build a system framework based on Asp.net MVC 4

B) integrates role-based permission management with RBAC to control the control level.

C) integrate some basic services: Data Dictionary, logging, etc.

D) Use AJAX features (using JQuery and MVC Partiview)

E) Plug-in mechanism: After the framework is built, the newly developed functional modules can be directly installed in the system framework as plug-ins for running.

F) Use EF Codefirst

Ii. System Design

A) RBAC-based permission management system

Refer to some permission management systems in the garden and useModule> resource> operationAs the most basic permission element, [resource, operation] as the basic permission atom, assign the permission atom to the "role"

To work with RBAC, inherit AuthorizeAttribute to modify Action

B) menu framework

This application framework is mainly designed for management systems. Therefore, the navigation menu is designed at two levels, the top navigation is a level-1 menu, the left side is a level-2 menu, and the menu can be associated with permissions, the menu can be affected when the configuration permission is set. Menu2 changes according to the selected Menu1;

C) Ajax framework

In this application framework, Content Area is the Ajax update Content. Use the $. get operation of JQuery to access the Action, return PartialView in the Action, and update it to ContentArea;

Using Ajax for loading all causes a problem. operations such as forward, backward, and refresh cannot be used. Using some information on the Internet, jquery is used. bbq. the js plug-in allows the system to maintain the status in the browser through the hashchange of the url, and can use operations such as "forward", "back", and "refresh; add the actual request code to the URL "#" to load the required content. The JS Code is as follows:

$ (Window ). bind ('hashchange', function (e) {var hash = window. location. hash | ''; if (oldHash ='') {// you need to select the default menu} if (hash! = ''& Hash! = OldHash) {if (hash = "# top") {// TODO, Load the index page !!!! Return;} Comment ('{contentpanel'}.html ('<div class = "wp">  & nbsp; loading... </div> '); oldHash = hash; $. get (hash. substr (1, hash. length-1), {}, function (data, status) {if (status = "success") {if (data. substr (0, 7) = '"logon"') {window. location = "/Home/Login";} else {response ('{contentpanel'}.html (data);} //} else {response ('{contentpanel'}.html ('error .. -'+ status) ;}}, "html") ;}}); $ (window ). trigger ('hashchange ');

 

In such a framework, you only need to pay attention to some views in the Content Area. In this Content Area, you can use Ajax + JSON to implement more functions;

Form Processing

Because the above AJAX mechanism is used, the previous form submission method cannot be used. In this framework, the following methods are used:

1) use the $. post (url, $ ('# form'). serialize (), callback, "html") method to update the returned value to the Content Area;

2) use the $. post (url, {'field1', 'value1 '}, callback, "json") method, and redirect the page through javascript based on the result;

D) A number of matching Helper

AjaxMenu, ajaxPager, etc.: because the above mechanism is used to load some views, all URLs must start with/Home #/Real/URL? Para1 = value1 is requested, so a Helper is written to complete this function. The same processing is required for paging.

E) IoC Container

In this example, the Unity Block is used as the IoC Container, because it is familiar with it. At the same time, the MVC and Unity Container are integrated;

F) Form Verification

Because the AJAX framework is used, most unobtrusive extension verification fails, so jquery. validate is directly used for client verification.

G) Plug-in mechanism

Define the IPlugin interface, including the Initialize method. Initialize the interface at system startup, such as Unity Container and MapRoute;

Plug-in usage: directly copy the plug-in to the plug-in directory in the framework, and copy the Views files required by the plug-in to the Views directory in the framework. (There is no better solution. Copy the code of the view engine in MVC to the plug-in directory to find the view)

Working principle: when the system starts, it loads the Dll in the plug-in through reflection, finds the IPlugin interface, and calls its initialization method. The plug-in registers the Controller to be used in the Unity container, in this way, the required controller and view can be called in the framework;

Plug-in format: The plug-in is also written using Asp.net mvc 4 Web APP. At last, only the compiled DLL and some necessary View views are used. Other resources use resources in the framework;

Iii. System implementation

1) Database: Uses EntityFramework (Version 5.0)-CodeFirst and Enable Migrations;

2) data access layer: defines the warehousing mode, and IRepository implements basic addition, deletion, query, and modification functions,

3) data service layer: defined as needed;

4) Portal: Use Asp.net MVC 4, Razor view engine, JQuery, JQuery UI, JQuery. Validate, jquery. bbq, and Jquery BlockUI;

5) Integrated CkEditor and CkFinder for content management

-------------------

Currently, the system code is still messy.

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.