[英]Is it possible to declare multiple routes for ASPNET.Core OData
I'm using the Microsoft.AspNetCore.OData 7.0.0 nuget package. 我正在使用Microsoft.AspNetCore.OData 7.0.0 nuget包。
I've registered my OData route prefix like the following. 我已经注册了我的OData路由前缀,如下所示。
app.UseMvc(routeBuilder =>
{
var builder = new ModelODataBuilder();
routeBuilder.EnableDependencyInjection();
routeBuilder.MapODataServiceRoute("ODataRoutes", "odata/Route1", builder.GetEdmModel(app.ApplicationServices));
});
Each OData Controller has a ODataRoutePrefix where the prefix corresponds to an EntitySet declared and configured in the GetEdmModel. 每个OData控制器都有一个ODataRoutePrefix,其前缀对应于在GetEdmModel中声明和配置的EntitySet。 For example
例如
[ODataRoutePrefix("Service1")]
However, I need some services to have a route prefix of "odata/Route1" while others have "odata/Route2". 但是,我需要某些服务的路由前缀为“ odata / Route1”,而其他服务的路由前缀为“ odata / Route2”。 For example
例如
http://odata/Route1/Service1 http://odata/Route2/Service2 http:// odata / Route1 / Service1 http:// odata / Route2 / Service2
I can't work out how to configure this. 我不知道如何配置它。 The following code does not work
以下代码不起作用
app.UseMvc(routeBuilder =>
{
var builder = new ModelODataBuilder();
routeBuilder.EnableDependencyInjection();
routeBuilder.MapODataServiceRoute("ODataRoute1", "odata/Route1", builder.GetEdmModelForRoute1(app.ApplicationServices));
routeBuilder.MapODataServiceRoute("ODataRoute2", "odata/Route1", builder.GetEdmModelForRoute2(app.ApplicationServices));
});
Does anyone know how I would configure this? 有人知道我将如何配置它吗?
I think I found a way. 我想我找到了办法。
added an extra app.UseMvc in my Startup.cs 在我的Startup.cs中添加了一个额外的app.UseMvc
app.UseMvc( b =>
{
b.Select( ).Expand( ).Filter( ).OrderBy( ).MaxTop( 100 ).Count( );
b.MapODataServiceRoute( "odata" , "odata" , EdmModelBuilder.GetEdmModel( app.ApplicationServices ) );
} );
app.UseMvc( b =>
{
b.Select( ).Expand( ).Filter( ).OrderBy( ).MaxTop( 100 ).Count( );
b.MapODataServiceRoute( "membership" , "membershipapi" , EdmModelBuilderMembership.GetEdmModel( app.ApplicationServices ) );
} );
It has been working so far... 到目前为止,它一直在工作...
You would also have to change your code so that you are not using the same path in both mappings: "odata/Route1" 您还必须更改代码,以免在两个映射中使用相同的路径:“ odata / Route1”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.