How to increase controller priority in MVC5.0

Source: Internet
Author: User

Homenamespace webapplication8.areas.weather.controllers{public class Homecontroller:controller established under Area    {        //get:weather/home public        actionresult Index ()        {            return Content GetType (). FullName);}}}    Homenamespace webapplication8.controllers{public class Homecontroller:controller created under the Controller file    {        //Get:home public              actionresult Index ()        {            return Content GetType (). FullName);}}}    

Run-time prompt:

According to the error we all know what is the reason, how to modify it, there are two ways, perhaps we all know is a kind of through the RouteTable.Routes.MapRoute method, to carry out namespaces constraints, such as:

public static void RegisterRoutes (RouteCollection routes)        {            routes. Ignoreroute ("{resource}.axd/{*pathinfo}");            Routes. MapRoute (                name: "Default",                URL: "{controller}/{action}/{id}",                defaults:new {controller = "Home", action = "Index", id = urlparameter.optional},                constraints:null,                namespaces:new string[] {" WebApplication8.Areas.Weather.Controllers "}            );        

By running, sure enough to recognize the right;

Just now there's another way to change that priority.

In the controller, there is the Controllerbuilder class that is responsible for registering the controller, through which he can register, and elevate the priority

Such as:

  protected void Application_Start ()        {            ControllerBuilder.Current.DefaultNamespaces.Add (" Webapplication8.controllers ");            Arearegistration.registerallareas ();            Routeconfig.registerroutes (routetable.routes);        }

Results:

,

But who has a higher priority, and I'm going to run chrome with both methods, and know that the Maproute registered by routing is higher priority.

How to increase controller priority in MVC5.0

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.