【问题标题】:route display 404 when upgrade asp.net mvc 3 to mvc 5将 asp.net mvc 3 升级到 mvc 5 时路由显示 404
【发布时间】:2014-05-27 10:56:03
【问题描述】:

您好,我在将我的项目从 asp.net mvc 3 升级到 mvc 5 时遇到问题

我的代码是

         routes.MapRoute(
           "Song", // Route name
           "{songid}.song", // URL with parameters
           new
           {
               controller = "Song",
               action = "Song",
           });

当我运行项目 iis 时显示 404 错误,但在 asp.net mvc 3 中它工作正常。 有什么想法吗?

【问题讨论】:

    标签: c# asp.net asp.net-mvc asp.net-mvc-5


    【解决方案1】:

    你的代码看起来像这样吗?

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.MapRoute(
                name: "Song",
                url: "{songid}.song",
                defaults: new { controller = "Song", action = "Song",
                        /*id = UrlParameter.Optional*/ }
            );
            routes.MapRoute(
                "Default",                                              // Route name
                "{controller}/{action}/{id}",                           // URL with parameters
                new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
            );
        }
    
        protected void Application_Start()
        {
            /// THE IMPORTANT PART
            RegisterRoutes(RouteTable.Routes);
        }
    }
    

    【讨论】:

    【解决方案2】:

    现在我发现我的错误是忘记改变

    <modules runAllManagedModulesForAllRequests="true" />
    

    在 web.config 中

    【讨论】:

    • 这是怎么解决的??
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-25
    • 2013-11-28
    • 2011-08-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多