0
爲什麼我的Web API中的第三條路由失敗?Web API中的屬性路由失敗2
public class StudentCourseController : ApiController
{
// GET api/student
public IEnumerable<StudentCourse> Get()
{
return StudentCourseRepository.GetAll();
}
// GET api/student/5
public StudentCourse Get(int id)
{
return StudentCourseRepository.GetAll().FirstOrDefault(s => s.Id == id);
}
[Route("StudentAuto/{key}")] // Does not work
public IEnumerable<Student> StudentAuto(string key)
{
return StudentRepository.GetStudentsAuto(key);
}
當我要求http://localhost:5198/api/StudentCourse/StudentAuto/mi
我收到404錯誤。
詳細錯誤顯示
Requested URL http://localhost:5198/api/StudentCourse/StudentAuto/mi
Physical Path C:\Users\deb\Desktop\StudentKO\KnockoutMVC\KnockoutMVC\api\StudentCourse\StudentAuto\mi
Logon Method Anonymous
Logon User Anonymous
我錯過了什麼?
感謝
任何鏈接/資源?我不能添加路由前綴到整個控制器。我的要求是在不破壞現有路線結構的情況下添加RPC風格的動作。 – Deb
完整路徑的工作。謝謝你的幫助。 – Deb
順便說一句,您可以指向我說的任何資源,它說屬性路由不適用於約束?我找不到您提供的MSDN鏈接。 – Deb