We have an ASP.net MVC app, and we are seeking to migrate it to ASP.net CORE due to client needs. Actually the app is providing REST services that are consumed by an AngularJS client app served by the same ASP.net app, it's little a mess actually. What should i opt for, Web API or MVC ? and if I choose Web API, can it serve static files ?
Thanks in advance!
To serve static files from an ASP.NET Core app, you must configure static files middleware. With static files middleware configured, an ASP.NET Core app will serve all files located in a certain folder (typically /wwwroot).
In ASP.NET Core, there's no longer any distinction between MVC and Web APIs. There's only ASP.NET MVC, which includes support for view-based scenarios, API endpoints, and Razor Pages (and other variations like health checks and SignalR). In addition to being consistent and unified within ASP.NET Core, APIs built in .
Static files, such as HTML, CSS, images, and JavaScript, are assets an ASP.NET Core app serves directly to clients by default.
First of all, Web Api and MVC is merge in ASP.NET Core.
To setup a solution which can run static files
Enable static files in the Configure method in the Startup.cs class, add:
app.UseStaticFiles();
Add the frontend solution (angularjs files, html etc) to the wwwroot folder.
Remove the default launchUrl (Properties/launchSettings.json) and set it to an empty string which will make the web server to look for the index.html file in the root instead
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