Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web APi Vs MVC and Serving static files in ASP.net core Web APi

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!

like image 783
khalil Avatar asked Dec 20 '17 09:12

khalil


People also ask

Which of the following Middlewares must be installed to serve static files in ASP.NET Core applications?

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).

What is the difference between ASP Net web API and ASP.NET Core web API?

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 .

Which of the following static files can ASP.NET Core applications serve?

Static files, such as HTML, CSS, images, and JavaScript, are assets an ASP.NET Core app serves directly to clients by default.


1 Answers

First of all, Web Api and MVC is merge in ASP.NET Core.

To setup a solution which can run static files

  1. Enable static files in the Configure method in the Startup.cs class, add:

    app.UseStaticFiles();
    
  2. Add the frontend solution (angularjs files, html etc) to the wwwroot folder.

  3. 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

like image 127
Marcus Höglund Avatar answered Nov 15 '22 04:11

Marcus Höglund