Search code examples
c#dotvvm

Redirect all the not found routes in dotvvm


How can I redirect all not found page requests to the same view?

This illustrates somehow what I mean:

config.RouteTable.Add("Home", "*", "Views/Home.dothtml", new { });

The idea behind is that when someone accesses a not existing page:

http://localhost/WhatEverNonExistingPage

The resquest is redirected to

http://localhost/Home

Solution

  • The only way I found so far is to implement it outside the dotvvm rules:

    appBuilder.Run(context =>
    {
        context.Response.Redirect("/Home");
        return Task.FromResult(0);
    });
    

    This means that basically any request not matching any route in the configured middlewares will be redirected to '/Home'. Not exactly the answer I was looking for, but it is effective.