我正在编写一个使用ASP.NET API的应用,我正在尝试对其进行调试。我以前没有使用过.NET。我的端点以/api/user
结尾。我应该如何找到相应功能在项目中的位置?我已经在项目中搜索了"user("
,但尚未找到任何内容。
有几种方法。
在方法或类上方搜索像[Route
或[Route("user")]
之类的注释的[Route("api/user")]
开头。
也可以是HttpGet
或HttpPost
(根据所使用的HTTP动词)而不是Route。
此外,默认情况下,路由名称也自动从控制器名称中派生。因此,搜索UserController类。
(名称的“ api”部分可能是在启动时或在服务器配置中定义的]
所以,我认为您最好的选择是找到这样的东西:
public class UserController : Controller
{
[HttpGet] // This will be the /user default endpoint for GET as per the controller name.
public IActionResult<User> MyGetTheUsersMethod() { /* method body here */ }
}
或者可能是类似:
[Route("user")]
public class MyFancyUserControllerClassName : Controller
{
[HttpGet] // This will be the /user default endpoint for GET as per the controller route.
public IActionResult<User> MyGetTheUsersMethod() { /* method body here */ }
}