Miniweb asp.net core

setup MVC to serve all URL's

View project on GitHub

Register a catchall route

In miniweb the goal is to serve all possible url's if there is a corresponding page in the stored pages

To set this us we need to register a "catchall" route to try to get the page for the current URL. We do this through one action method that returns all pages.
One gotcha is that all other resource routes, like the embedded assets, should be registered before the final catchall route

public void Configure(IApplicationBuilder app)
{
    app.UseMvc(routes =>
    {
        routes.MapRoute("miniweb", "{*url}", new { controller = "MiniWebPage", action = "Index" });
    }
}

The only real thing left to do is creating the Controller and Index action method, and handle the URL parameter, show a view based on the URL.

You can add an extra constrained to only serve .html pages like constraints: new { url = ".*?\\.html(\\?.*)?" });

Thanks,

Rooc