Frank Chen
1 min readSep 14, 2018

--

I am glad you like my article. the original post was targeting on a idea to separate SPA and Web API as two projects. that’s why when you looked at the code in startup.cs, the setting will focus on a SPA. if you created a web api controller, it won’t be able to load.

if you need to allow web api controller to be routed properly. you probably need to look at the below startup.cs

public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddSpaStaticFiles(configuration =>
{
configuration.RootPath = “ClientApp/dist”;
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler(“/Error”);
//app.UseHsts();
}
//app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseSpaStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: “default”,
template: “{controller}/{action=Index}/{id?}”);
});
app.UseSpa(spa =>
{
// To learn more about options for serving an Angular SPA from ASP.NET Core,
// see https://go.microsoft.com/fwlink/?linkid=864501
spa.Options.SourcePath = “ClientApp”;if (env.IsDevelopment())
{
//spa.UseAngularCliServer(npmScript: “start”);
spa.UseProxyToSpaDevelopmentServer(“http://localhost:4200”);
}
});

}
}

I hope it helps.

--

--

Responses (1)