这是我修改的默认路由器:
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}/{addParam}",
defaults: new { id = RouteParameter.Optional, addParam = RouteParameter.Optional }
);
这是控制器:
public class ReviewCycleController : ApiController
{
private MrdSearchServices _mrss = new MrdSearchServices();
// GET api/reviewcycle
public IQueryable<MrdReviewCycle> GetReviewCycles()
{
return _mrss.GetAllReviewCycles();
}
// GET api/reviewcycle/Active
public MrdReviewCycle GetReviewCycle(String is_active)
{
if (!is_active.ToLower().Equals("active"))
{
string url = new Uri(Request.RequestUri, "/api/ReviewCycle/Active").ToString();
var resp = new HttpResponseMessage(HttpStatusCode.NotFound)
{
Content = new StringContent(string.Format("No Review Cycle with State of '{0}' could be found. The only acceptable value is 'Active'. Request should be made to {1}.", is_active, url)),
ReasonPhrase = "Review Cycle Not Found!"
};
throw new HttpResponseException(resp);
}
return _mrss.GetActiveReviewCycle();
}
}
但是当我打电话时:http://localhost:2515/api/ReviewCycle/asdf
或者http://localhost:2515/api/ReviewCycle
我没有得到预期的结果。我得到的都是return _mrss.GetActiveReviewCycle();
.
我到底做错了什么?
谢谢埃里克