I have my .Net Core API and my Angular site all built and running locally. Now I want to publish to an .Net Hosting provier, not Azure. So would the best way be to enable static content and then build my Angular app and drop it in the wwwroot of the API solution?
side notes: Im using .net core 2.x, if that matters. And, by Angular I mean Angular2 not AngularJS. Is this standard terminology yet? :-)
To answer your question, yes, you should enable static content and build your Angular app and files out to wwwroot
.
This is the simplest Startup
you can use to serve an Angular app on .NET Core 2.0.
public class Startup
{
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
// this will serve wwwroot/index.html when path is '/'
app.UseDefaultFiles();
// this will serve js, css, images etc.
app.UseStaticFiles();
// this ensures index.html is served for any requests with a path
// and prevents a 404 when the user refreshes the browser
app.Use(async (context, next) =>
{
if (context.Request.Path.HasValue && context.Request.Path.Value != "/")
{
context.Response.ContentType = "text/html";
await context.Response.SendFileAsync(
env.ContentRootFileProvider.GetFileInfo("wwwroot/index.html")
);
return;
}
await next();
});
}
}
As you can see there's no need for MVC or razor views.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With