How do you set the startup page for debugging in an ASP.NET MVC application?

后端 未结 6 1921
伪装坚强ぢ
伪装坚强ぢ 2020-11-29 21:47

How do you start debugging the application at the application root? For example: http://localhost:49742/

I\'m always getting a page which doesn\'t e

6条回答
  •  既然无缘
    2020-11-29 22:18

    While you can have a default page in the MVC project, the more conventional implementation for a default view would be to use a default controller, implememented in the global.asax, through the 'RegisterRoutes(...)' method. For instance if you wanted your Public\Home controller to be your default route/view, the code would be:

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    
            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Public", action = "Home", id = UrlParameter.Optional } // Parameter defaults
            );
    
        }
    

    For this to be functional, you are required to have have a set Start Page in the project.

提交回复
热议问题