簡體   English   中英

Asp.Net Core 5 使用應用程序部件注冊控制器

[英]Asp.Net Core 5 Registering Controllers using Application Parts

我正在使用 Asp.net 核心 web api 開展項目,在我的解決方案中,我有多個項目,每個項目都有自己的控制器類。 I added a controller class Named AccountController and registered it using a application part and it registered the controller as a application part but I have other controller class Profile Controller it does not registering.

public static IServiceCollection AddAuthenticationControllers(this IServiceCollection services)
    {
        services.AddControllers().AddApplicationPart(typeof(ProfileControllers).Assembly);
        
        services.AddControllers().AddApplicationPart(typeof(AccountControllers).Assembly);
        

        return services;
    }

以下是上述行的調試結果。

profilecontroller 組件的調試結果

AccountController 程序集的調試結果

在圖 2 中可以看到 Account controller 組裝結果是紅色的。 當我從 postman 中點擊 accountcontroller 的 api 時,它成功執行,但是當我點擊 profilecontroller 的 api 時,它給出 404 錯誤。

嘗試這個:

services.AddControllers()
   .AddApplicationPart(typeof(ProfileControllers).Assembly)
   .AddApplicationPart(typeof(AccountControllers).Assembly);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM