我在解决方案中有各种项目(ASP.Net MVC,域,数据库,实体和Telerik Report Server WebApi)。
ASP.Net MVC托管在主机名/和报告服务器主机名/ ReportServer /
除报表服务器外,一切正常。
它将ReportsController API置于
/ReportServer/Controllers/ReportsController
而不是
/ReportServer/api/ReportsController
我创建了一个简单的测试解决方案,只有一个ASP.Net MVC和ReportServer,理论上具有相同的设置。这有效,但我看不出是什么造成了这种情况。所有的路线,基类等都是一样的。
有什么想法吗?
答案 0 :(得分:2)
您可以编写自己的路径注册过程,并从WebApiConfig.Register(在DefaultApi路由之前)调用它,而不是调用默认的Telerik报告路由注册功能(ReportsControllerConfiguration.RegisterRoutes)。例如:
private static void RegisterReportingRoutes(HttpConfiguration config)
{
config.Routes.MapHttpRoute(name: "Clients",
routeTemplate: "ReportServer/Controllers/{controller}/clients/{clientID}",
defaults: new { controller = "MyCustomReports", action = "Clients", clientID = RouteParameter.Optional });
config.Routes.MapHttpRoute(
name: "Instances",
routeTemplate: "ReportServer/Controllers/{controller}/clients/{clientID}/instances/{instanceID}",
defaults: new { controller = "MyCustomReports", action = "Instances", instanceID = RouteParameter.Optional });
config.Routes.MapHttpRoute(
name: "DocumentResources",
routeTemplate: "ReportServer/Controllers/{controller}/clients/{clientID}/instances/{instanceID}/documents/{documentID}/resources/{resourceID}",
defaults: new { controller = "MyCustomReports", action = "DocumentResources" });
config.Routes.MapHttpRoute(
name: "DocumentActions",
routeTemplate: "ReportServer/Controllers/{controller}/clients/{clientID}/instances/{instanceID}/documents/{documentID}/actions/{actionID}",
defaults: new { controller = "MyCustomReports", action = "DocumentActions" });
config.Routes.MapHttpRoute(
name: "DocumentPages",
routeTemplate: "ReportServer/Controllers/{controller}/clients/{clientID}/instances/{instanceID}/documents/{documentID}/pages/{pageNumber}",
defaults: new { controller = "MyCustomReports", action = "DocumentPages" });
config.Routes.MapHttpRoute(
name: "DocumentInfo",
routeTemplate: "ReportServer/Controllers/{controller}/clients/{clientID}/instances/{instanceID}/documents/{documentID}/info",
defaults: new { controller = "MyCustomReports", action = "DocumentInfo" });
config.Routes.MapHttpRoute(
name: "Documents",
routeTemplate: "ReportServer/Controllers/{controller}/clients/{clientID}/instances/{instanceID}/documents/{documentID}",
defaults: new { controller = "MyCustomReports", action = "Documents", documentID = RouteParameter.Optional });
config.Routes.MapHttpRoute(
name: "Parameters",
routeTemplate: "ReportServer/Controllers/{controller}/clients/{clientID}/parameters",
defaults: new { controller = "MyCustomReports", action = "Parameters" });
config.Routes.MapHttpRoute(
name: "Formats",
routeTemplate: "ReportServer/Controllers/{controller}/clients/{clientID}/formats",
defaults: new { controller = "MyCustomReports", action = "Formats" });
config.Routes.MapHttpRoute( name: "EditingAndLayout", routeTemplate: "ReportServer/Controllers/{controller}/formats", defaults: new { controller = "MyCustomReports", action = "Formats" });
}
如果/ ReportServer路径是它自己的Web应用程序,而不是" /"应用程序,然后你可以省略" ReportServer /"上面注册功能的一部分
答案 1 :(得分:1)
在ASP.Net Web API路由的情况下,文件夹结构/名称没有意义。
您无需将其放在“controller”文件夹或“API”文件夹中。如果您注意到WebAPI.config文件中的路由配置,则默认路由模板将类似于“api/{controller}/{id}
”,这将使您的api路由正常工作。
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}", // <--
defaults: new { id = RouteParameter.Optional }
);