2013-06-21 66 views
3

我剛剛工作的一個新的控制器操作方法,我爲什麼我看到一個405MVC AttributeRouting用GET - 返回405 - 不允許的方法

我已經定義了幾個會有點困惑我的API已被賦予方法,它們都按預期運行。舉一個例子能正常工作:

[GET("entries/{page}"), JsonExceptionFilter] 
    public HttpResponseMessage GetEntries(int page) 

然而,像這樣定義我的新方法:

[GET("search/{searchTerm}/{page}"), JsonExceptionFilter] 
    public HttpResponseMessage Search(string searchTerm, int page) 

返回一個405

如果我訪問的API的routes.axd網址我可以看到表中的條目是這樣的:

GET, HEAD, OPTIONS users/search/{searchTerm}/{page} 

這一切都看起來正確。在客戶端,我使用的是兩個請求同樣的方法使用的HttpClient:

var response = httpClient.GetAsync(ApiRootUrl + "users/search/" + searchTerm + "/" + page).Result; 

運行從提琴手的獲取也返回一個405

甚至打算在響應中RequestMessage看起來是正確的:

"{Method: GET, RequestUri: 'http://localhost:51258/users/search/jam/0'" 

完全難住這個。

我還可以嘗試什麼,也許可以揭示哪些問題?

回答

相關問題