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 关注
- 248 浏览
添加回答
举报