The requests in Asp.net are based on physical files (. aspx). Therefore, a basic request corresponds to a specific file in the application.
Therefore, in Asp.net, there is no special management requirement for user requests. You only need to manage the physical files of the application.
In MVC, all these fundamental changes occur. User requests have nothing to do with physical files, and because of this feature, you can organize them at will.
The URL requested by the user. Unordered route settings can lead to disorder in your program. Therefore, in MVC, URL management is necessary.
The following are my summary methods.
1. A hierarchy is required.
For building an enterprise website, it is generally divided into the front-end and back-end. The front-end interface is used for anonymous users or registered users, and then the website administrator performs website data.
Operation interface. Generally, the frontend is in the form of http://www.site.com/xxxx. Background: http://www.site.com/admin/xxxx.
XXXX indicates the specific access content.
The foreground settings are as follows:
Home: http://www.site.com/or http://www.site.com/index
Company Profile: http://www.site.com/about
Company: http://www.site.com/news
Products: http://www.site.com/product
We: http://www.site.com/contat
......
Background
Login: http://www.site.com/admin/login
Product maintenance: http://www.site.com/admin/product
Http://www.site.com/admin/news
2. Reasonably match the url and controller
The Controller of MVC is located based on the Controller name. Therefore, the name and action of the Controller should not conflict with the access path defined in the front.
We use a website as an example. Because the structure is divided into foreground and background, we define the Controller as the frontend and background. Home is used at the front end and manage is used at the backend.
Home actions include Index, News, Product, ShowNews, ShowProduct (), About, and Contract.
Manage actions include Login, Product, ProductDetail, and AddProduct.
3. Routetable
Front-end
Routes. MapRoute (
"Home", // Route name
"{Action}/{Id}", // by default, the root site is sent to Home
New {controller = "Home", action = "Index", id = UrlParameter. Optional} // set the hosts page.
);
Background
Routes. MapRoute (
"Admin", // Route name
"Admin/{action}/{Id}", // hand over admin processing to Manager by default
New {controller = "Manage", action = "Index", id = UrlParameter. Optional} // set the hosts page.
);