![](/img/trans.png)
[英]How do I test the integration between the Global error handling middleware and my controller in ASP.Net Core?
[英]How do I tell the MVC middleware that my class is a Controller in ASP.NET Core?
我如何告訴 MVC 中間件我的 class 是 ASP.NET Core 中的一個 Controller?
根據ASP.NET Core in Action
一書:
控制器是普通類,盡管它們通常繼承自 Controller 基類 class 以提供對許多輔助方法的訪問,如以下清單所示。
我以為我們通過繼承Controller
class 告訴 MVC 我們的 class 是一個 controller。但現在我發現我錯了,Controller 883911812195 的Controller
是可選的。
這意味着還有其他因素使 MVC 中間件將類視為控制器,將它們的方法視為操作方法,從而使 MVC 中間件根據傳入請求路徑檢查相應的類和方法。 但我無法理解或在 inte.net 上找到這是什么。
我覺得很有可能。 你不需要繼承自Controller
或ControllerBase
例如,你可以簡單地這樣做:
public class ProductController{}
這里的關鍵是后綴Controller 。
或者您可以使用ControllerAttribute
。 像這樣:
[Controller]
public class Product{}
還有其他一些方法可以實現這一點。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.