Asp.net MVC 3 Use Area Summary

Source: Internet
Author: User

The project is divided into three home pages

For example:/Home/Index front-end Homepage

/Admin/Home/Index background Homepage

/OA/Home/Index Office Platform Homepage

Create an asp.net MVC3 example project: Right click → add → Area

Run the project directly:

The reason is that multiple controllers with the same name exist, and the default namespace needs to be configured. Solution:

Open Global. asax. cs

Public static void RegisterRoutes (RouteCollection routes)
{
Routes. IgnoreRoute ("{resource}. axd/{* pathInfo }");

Routes. MapRoute (
"Default", // Route name
"{Controller}/{action}/{id}", // URL with parameters
New {controller = "Home", action = "Index", id = UrlParameter. Optional}, // Parameter defaults
New [] {"Web. Controllers"} // Namespaces introduces the default namespace
);

}

Http: // localhost: 49849/output after runningHome/Index

Http: // localhost: 49849/Admin/Home/Index output after runningAdmin/Home/Index

Http: // localhost: 49849/OA/Home/Index output after runningOA/Home/Index

Change path:

Http: // localhost: 49849/Admin/www.2cto.com and the system Returns Error 404.

The reason is that the Admin in Area does not configure the default Controller. solution:

Open Admin under AreaAdminAreaRegistration. cs

New {controller = "Home", action = "Index", id = UrlParameter. Optional}

Add the default Controller.

Here, I will discuss it.

From: BirchLee's personal blog

Related Article

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.