应用程序找不到位于另一个项目中的 Razor 页面

Joh*_*riz 4 c# razor asp.net-core razor-pages

我正在从事 Razor Pages 项目。该解决方案由多个项目组成,即“Server”,它管理依赖注入的服务,是一个启动项目。“应用程序”包含索引页面和共享组件,以及多个“模块”项目,它们是站点的独立区域。我需要向该解决方案添加新模块以及登陆页面。我创建了新项目,设置了对解决方案中其他项目的所有引用,并使用“@page”/moduleC”行创建了一个页面。但是如果我运行解决方案并转到该页面 - 它会显示 404 页面。相同的配置可以与其他模块配合使用。是否需要一些额外的操作来允许在多个项目之间进行路由?

小智 5

https://digitteck.com/frontend/blazor/blazor-page-in-another- assembly/

Router 组件负责映射 Razor 页面。

您将需要使用AdditionalAssemblies 参数添加其他程序集。

<CascadingAuthenticationState>
    <Router AppAssembly="@typeof(Program).Assembly" AdditionalAssemblies="@_extraAssemblies">
        <Found Context="routeData">
           ...
        </Found>
        <NotFound>
            ...
        </NotFound>
    </Router>
</CascadingAuthenticationState>

@code{

    private List<System.Reflection.Assembly> _extraAssemblies = new List<System.Reflection.Assembly>()
    {
        typeof(OtherProject.SomeObjectInOtherProject).Assembly,
    };

}
Run Code Online (Sandbox Code Playgroud)