Configuring the ASP.NET Core pipeline

So far, we have configured our client-side packages. In ASP.NET Core, we can add static files, security and MVC middleware. To implement security in an ASP.NET Core project, please refer to Chapter 10, Security Practices with .NET Core.

When developing an SPA application, we use the client-side framework heavily for routing  modules and template rendering. Many client-side frameworks, such as Angular, provide their own routing modules to render pages in the main parent container. To enable those routing, we need to add the following spa-fallback entry followed by our MVC entry as shown next:

    app.UseMvc(routes => 
{
routes.MapRoute("default", "{controller=Home}/
{action=Index}/{id?}");
routes.MapRoute("spa-fallback", "{*anything}",
new { controller = "Home", action = "Index" });
});

Moreover, static files middleware should be added so all the static files, such as images, JavaScript, and CSS, can be loaded:

    app.UseStaticFiles();
Static files middleware should be added before the MVC middleware in the pipeline.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.247.68