簡體   English   中英

Web API中的路由/操作已損壞

[英]Broken Routing/Action in Web API

我在WebApiConfig.cs中定義了我的默認路由:

        config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional, page = 20, offset = 0 }
        );

在我的控制器中,我有一個動作:

    // GET api/users
    [HttpGet]
    public IEnumerable<User> Get(string id, int page, int offset)
    {
        return id != null 
            ? new User[]{Get(id)} 
            : _userService.All().Skip(offset*page).Take(page);
    }

我知道這最近工作,但現在我得到了臭名昭着的“沒有找到控制'用戶'匹配請求的行動”錯誤。 我似乎無法想象什么(如果有的話)改變了。 自從添加頁面/偏移的默認值以來,我已經撤消了所有更改,但仍然沒有。

有任何想法嗎?

請求網址: http://localhost/api/api/Users

這里參數'id'是可選的,但是動作選擇器期望在動作上為它指定默認值。

public IEnumerable Get(string id = null ,int page,int offset)

另外關於url,可能是拼寫錯誤,你的意思是http://localhost/api/Users而不是http://localhost/**api/api**/Users

您尚未在路線中指定行動。 您需要在URL中添加{action}部分,或在default對象中指定操作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM