用于两个或多个控制器方法的ASP.MVC WebAPI Odata路由

时间:2019-01-16 08:12:10

标签: asp.net-web-api odata asp.net-web-api-routing

我正在尝试向我的odata Web服务添加新路径,并且现在已经很困惑了。

如果我只有一种方法-一切都很好。这是我的代码

//webapiconfig.cs
   config.MapHttpAttributeRoutes();
   config.Filter().Expand().Select().OrderBy().MaxTop(null).Count();
   var userInfo = builder.EntitySet<UserInfo>("Users");
            userInfo.EntityType.HasKey(x => new { x.TN });
            config.MapODataServiceRoute(
                routeName: "ODataRoute",
                routePrefix: "odata/",
                model: builder.GetEdmModel());

    //usercontroller
    [EnableQuery(
            EnableConstantParameterization = true,
            PageSize = 100,
            AllowedQueryOptions = AllowedQueryOptions.Top | AllowedQueryOptions.Filter | AllowedQueryOptions.Skip,
            AllowedArithmeticOperators = AllowedArithmeticOperators.None,
            AllowedLogicalOperators = AllowedLogicalOperators.Equal | AllowedLogicalOperators.Or | AllowedLogicalOperators.And,
            AllowedFunctions = AllowedFunctions.StartsWith | AllowedFunctions.ToLower)]
    [ODataRoute("Users/UsersInfo")]
        public IQueryable<UserInfo> GetUserInfo(ODataQueryOptions<UserInfo> queryOptions)
        {
            //business logic
        }

如果我尝试添加新方法-它根本不响应

[EnableQuery]
[ODataRoute("Users/OtherUsers")]
public IQueryable<UserInfo> GetOtherUser() {
     //business logic   
    }

我尝试使用ODataRoute属性,但没有成功。充其量我得到“发现多个与请求错误匹配的动作”。  让我感到烦恼的是-Web服务会响应http://localhost/odata/Users/路由并为http://localhost/odata/Users/UsersInfohttp://localhost/odata/Users/OtherUsers返回相同的结果。

我认为我在webapiconfig中犯了一些错误,但是无法弄清楚到底是什么

0 个答案:

没有答案