如何从中间件获取ASPNETCORE OData请求的路由数据?

时间:2018-05-21 23:51:00

标签: asp.net-core odata asp.net-core-middleware

我有以下中间件类,它获取当前请求的路由数据。

如果执行值控制器上的Get,您将看到context.GetRouteData()返回一个值,而不是null。我已将Swagger \ Swashbuckle连接到附加的项目中,以便更容易演示。

但是,如果您调用博客OData控制器(http://localhost:40946/odata/Blog),则context.GetRouteData()将返回null。

有没有人知道如何从中间件访问RouteData以获取OData请求?

public class TestMiddleware
{
    protected readonly RequestDelegate _next;

    public TestMiddleware(RequestDelegate next)
    {
        this._next = next;
    }

    public virtual async Task Invoke(HttpContext context)
    {
        var routeData = context.GetRouteData();

        await this._next.Invoke(context);
    }
}

Link to sample solution demonstrating the issue

1 个答案:

答案 0 :(得分:0)

看起来OData中间件没有将路由信息作为IRoutingFeature提供给上下文。 Link to Source Code

不确定根本原因 - 但作为解决方法,您可以使用

    d<-function(x,y){
          aux=x-y
          sum(aux*aux)
    }

    ##Radial Basis Function Kernel
    # Remember :
    # 1.K(x,x')=exp(-q||x-x'||^2) where ||x-x'|| is could be defined as the
    # euclidian distance and 'q' it's the gamma parameter
    rbf<-function(x,y,q=0.2){
            aux<-d(x,y)
            rbfd<-exp(-q*(aux))
            return(rbfd)
    }
相关问题