本帖最后由 KearneyKang 于 2021-6-23 10:00 编辑
项目代码路径https://github.com/activereports ... les/WebDesigner_MVC
事例一:路由使用routes.MapMvcAttributeRoutes();增加路由{controller}/{action}/{id};报表api接口404
解决方案:1、增加类
- public class RouteConfig2
- {
- public static void RegisterRoutes(RouteCollection routes)
- {
- routes.MapRoute(
- name: "Default",
- url: "{controller}/{action}/{id}",
- defaults: new { controller = "Design", action = "Index", id = UrlParameter.Optional }
- );
- }
- }
复制代码
2、Startup.cs文件的Configuration方法最后面加代码
- RouteConfig2.RegisterRoutes(RouteTable.Routes);
- RouteTable.Routes.RouteExistingFiles = true;
复制代码
事例二:路由不用routes.MapMvcAttributeRoutes();增加路由{controller}/{action}/{id};报表api接口404
解决方案:
1、类修改RouteConfig
- public class RouteConfig
- {
- public static void RegisterRoutes(RouteCollection routes)
- {
- //routes.MapMvcAttributeRoutes();
- routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
- routes.MapRoute(
- name: "Design",
- url: "",
- defaults: new { controller = "Design", action = "Index" }
- );
- routes.MapRoute(
- name: "DesignCreate",
- url: "create",
- defaults: new { controller = "Design", action = "Create", id = UrlParameter.Optional }
- );
- routes.MapRoute(
- name: "DesignEdit",
- url: "edit/{id}",
- defaults: new { controller = "Design", action = "Edit", id = UrlParameter.Optional }
- );
- routes.MapRoute(
- name: "DesignResource",
- url: "{file}",
- defaults: new { controller = "Design", action = "Resource", id = UrlParameter.Optional }
- );
- routes.MapRoute(
- name: "DataSetsGetDataSetsList",
- url: "api/datasets/list",
- defaults: new { controller = "DataSets", action = "GetDataSetsList", id = UrlParameter.Optional }
- );
- routes.MapRoute(
- name: "TemplatesGetTemplatesList",
- url: "api/templates/list",
- defaults: new { controller = "Templates", action = "GetTemplatesList", id = UrlParameter.Optional }
- );
- routes.MapRoute(
- name: "DataSetsGetDataSetContent",
- url: "api/datasets/{id}/content",
- defaults: new { controller = "DataSets", action = "GetDataSetContent", id = UrlParameter.Optional }
- );
- routes.MapRoute(
- name: "TemplatesGetTemplate",
- url: "api/templates/{id}/content",
- defaults: new { controller = "Templates", action = "GetTemplate", id = UrlParameter.Optional }
- );
- routes.MapRoute(
- name: "TemplatesGetTemplateThumbnail",
- url: "api/templates/{id}/thumbnail",
- defaults: new { controller = "Templates", action = "GetTemplateThumbnail", id = UrlParameter.Optional });
- }
复制代码 2、增加类
- public class RouteConfig2
- {
- public static void RegisterRoutes(RouteCollection routes)
- {
- routes.MapRoute(
- name: "Default",
- url: "{controller}/{action}/{id}",
- defaults: new { controller = "Design", action = "Index", id = UrlParameter.Optional }
- );
- }
- }
复制代码 3、Startup.cs文件的Configuration方法最后面加代
- RouteConfig2.RegisterRoutes(RouteTable.Routes);
- RouteTable.Routes.RouteExistingFiles = true;
复制代码
完毕!!
如有疑问联系QQ546962925
|