3 回答

TA貢獻1851條經驗 獲得超3個贊
您需要將此代碼用于ASP.NET Core 2.0,而不是您正在使用的代碼。我的應用程序是使用這種方法發布的。
app.UseMvc(routes =>
{
//Remove this if you don't need it
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
routes.MapSpaFallbackRoute(
name: "spa-fallback",
defaults: new { controller = "Home", action = "SPAIndex" }); // For SPA
});
您需要在 HomeController 中有一個返回視圖的操作。查看代碼是
<app asp-prerender-module="ClientApp/dist/main-server">Loading...</app>

TA貢獻1856條經驗 獲得超11個贊
只需進行此更改,它應該適用于 Prod IIS
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
// In production, the Angular files will be served from this directory
services.AddSpaStaticFiles(configuration =>
{
configuration.RootPath = "ClientApp/dist/client";
});
}

TA貢獻1864條經驗 獲得超6個贊
Visual Studio 2019 為此提供了一個項目模板,只需在開始頁面的第一步中選擇新建項目,ASP.NET Core Web Application C#,輸入解決方案名稱,然后選擇 Angular 項目模板。您可以將解決方案基于在 .NET Core 或 .NET Framework 下運行的 ASP.NET Core。
- 3 回答
- 0 關注
- 278 瀏覽
添加回答
舉報