For a traditional controller-based Web API in .NET 8/9, which method call in Program.cs is essential for routing to controllers?
4 phương ánCó giải thích
Các phương án trả lời
Chọn một phương ánLời giảiChọn phương án để mở
Trong một ứng dụng Web API truyền thống dựa trên controller trong .NET 8/9, phương thức gọi trong Program.cs quan trọng nhất cho việc định tuyến đến các controller là app.MapControllers(). Phương thức này cho phép ứng dụng nhận biết và xử lý các yêu cầu HTTP đến các controller. Khi bạn gọi app.MapControllers(), bạn đang cho phép ứng dụng .NET sử dụng tính năng routing mặc định để định tuyến các yêu cầu đến các controller phù hợp. Điều này giúp bạn có thể sử dụng các controller để xử lý các yêu cầu HTTP và trả về các phản hồi phù hợp.
Cùng chương 4
A controller action needs to return a "Not Found" response when a resource does not exist. Which of the following is the best way to achieve this? [HttpGet("{id}")] public ActionResult<Product> GetProduct(int id) { var product = _productService.GetById(id); if (product == null) { return ???; // What should be here? } return product; }Câu hỏiAccording to inference rules, any complex type parameter NOT registered in the DI container and NOT matching a route parameter will be inferred as coming from where?Có lời giảiCâu hỏiGiven the action public IActionResult Get(int id), and no other attributes, where will the model binder look for the value of id by default?Có lời giảiCâu hỏiCả 19 câu của chủ đề19 câu