我的Web应用程序中有多个路径控件用于多个操作。
此操作由参数 -
调用 routes.MapRoute(
name: "SpecificRoute",
url: "{BusinessName}",
defaults: new { controller = "Business", action = "OpenPage" }
);
通过action
名称和参数 -
routes.MapRoute(
name: "ResumeRoute",
url: "{action}/{PublicResume}",
defaults: new { controller = "Business", action = "PublicResume" }
);
对于所有默认操作,默认情况下我已经有一个路由控件 -
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{*id}",
defaults: new { controller = "WelcomeLedger", action = "Welcome", id = UrlParameter.Optional }
);
我已在本地IIS服务器上部署此应用程序。
现在route.config
文件出现了问题,也许我没有以正确的方式使用路由。
因此,此应用程序会在每个操作上显示resource not found error
,有时在清理解决方案后会起作用。
如何在不违反使用方式的情况下使用操作?
这是我的route.config文件 -
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Routing;
namespace MvcApplication8 {
public class RouteConfig {
public static void RegisterRoutes(RouteCollection routes) {
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });
routes.MapRoute(
name: "SpecificRoute",
url: "{BusinessName}",
defaults: new { controller = "Business", action = "OpenPage" }
);
routes.MapRoute(
name: "ResumeRoute",
url: "{action}/{PublicResume}",
defaults: new { controller = "Business", action = "PublicResume" }
);
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{*id}",
defaults: new { controller = "WelcomeLedger", action = "Welcome", id = UrlParameter.Optional }
);
}
}
}
修改 -
在其上方添加两条自定义路由后找不到默认路由(resource not found
)。
答案 0 :(得分:1)
我认为您的默认路线中有拼写错误:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{*id}",
defaults: new { controller = "WelcomeLedger", action = "Welcome", id = UrlParameter.Optional }
);
在ID之前有*,它应该是{id}
而不是{*id}