Odata路由配置(netcore)

时间:2019-05-15 08:11:36

标签: c# asp.net-core odata

我尝试配置OData。使用RouteAnalyzer发现我需要的路由已注册(/ My / Test)。但是当我尝试在浏览器中打开它时,我只会得到404。

任何人都可以向我解释哪里有问题吗?

有我的控制器和配置。

Startup.cs:

 public class Startup
{
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    public void ConfigureServices(IServiceCollection services)
    {
        ConfigureOptions(services);

        services.AddRouteAnalyzer();
        services.AddOData();
        services.AddODataQueryFilter();

        services.AddMvc();
    }

    private void ConfigureOptions(IServiceCollection services)
    {
        services.AddOptions()
                .Configure<SqlConnectionOption>(Configuration.GetSection(nameof(SqlConnectionOption)));
    }

    public void ConfigureContainer(ContainerBuilder containerBuilder)
    {
        containerBuilder.RegisterAssemblyModules(typeof(DbInstaller).GetTypeInfo().Assembly);
    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
            app.UseDeveloperExceptionPage();
        else
            app.UseHsts();

        app.UseHttpsRedirection();
        app.UseMvc(routeBuilder =>
            {
                routeBuilder.MapRouteAnalyzer("/routes");
            }
        );
    }

和端点:

 [ODataRoutePrefix("My")]
public class MyController: ODataController
{

    [HttpGet]
    [ODataRoute("Test")]
    public string Test() => "AllOk";
}

0 个答案:

没有答案