0

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
Cristian T
  • 2,245
  • 3
  • 25
  • 45
  • Is this useful to you? http://stackoverflow.com/questions/11045733/404-redirecting-for-non-aspx-pages – Danieboy Jul 22 '16 at 17:17
  • thanks for your reply, dotvvm can run on Owin so you don't necessarily need IIS to host it. I don't know if the approach works with dotvvm+IIS but in my case the web.config is not used. – Cristian T Jul 22 '16 at 17:25

2 Answers2

1

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.

Cristian T
  • 2,245
  • 3
  • 25
  • 45
0

Since DotVVM is Owin you can use it with Nancy. Any routes that aren't matched in DotVVM get passed on to Nancy. You can then use Nancy to handle your 404's or any other types you may need such as 301's if you are rebuilding a site.

It's a somewhat long-winded approach but if you are writing a hybrid app with micro services then it might make sense.

Setting up:

https://github.com/riganti/dotvvm-samples-combo-with-nancy

Handling custom 404's in Nancy.

https://blog.terribledev.io/custom-error-pages-in-nancy/

Norbert Norbertson
  • 2,102
  • 1
  • 16
  • 28