Wil*_*iam 8 c# routing asp.net-core
我的控制器上有很多操作,如果可能的话,我只想将特定路由用于一个操作。我正在寻找一种方法来覆盖在控制器级别定义的路由。
[Route("api/candidate/attached-file")]
public class AttachedFileController : Controller
{
//overriding controller route
[HttpPost("api/candidate/{id}/attached-file")]
public async Task<IActionResult> AttachFile(string id, [FromBody] AttachedFile file)
{
...
}
//using controller route
[HttpGet("{id}")]
public ActionResult Get(string id) {}
[HttpGet]
public ActionResult GetAll() {}
...
}
Run Code Online (Sandbox Code Playgroud)
小智 10
为了忽略控制器使用的路由方法,如下所示:
[Route("/api/customControllerName/getCustomMethodName")]
public ActionResult GetCustomAll() {
}
Run Code Online (Sandbox Code Playgroud)
使用 [Route("/")] 忽略 api 路由寻址。
[Route("api/candidate/attached-file")]
public class AttachedFileController : Controller
{
//overriding controller route
[HttpPost("api/candidate/{id}/attached-file")]
public async Task<IActionResult> AttachFile(string id, [FromBody] AttachedFile file)
{
...
}
//using controller route
[HttpGet("{id}")]
public ActionResult Get(string id) {}
[Route("/api/test/value")]
public ActionResult GetCustomAll() {
}
}
Run Code Online (Sandbox Code Playgroud)
因此,通过调用 api/test/value 地址 GetCustomAll() 方法将被调用。
归档时间: |
|
查看次数: |
1921 次 |
最近记录: |