From dcfc22174865cd0a6e2be1acd0f070cafd13af81 Mon Sep 17 00:00:00 2001 From: Mark Zhukovsky Date: Tue, 25 Dec 2018 21:54:17 +0800 Subject: [PATCH] docs: add .net mvc example server config for history mode --- docs/guide/essentials/history-mode.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/docs/guide/essentials/history-mode.md b/docs/guide/essentials/history-mode.md index 759c9ea16..d7c95b9f9 100644 --- a/docs/guide/essentials/history-mode.md +++ b/docs/guide/essentials/history-mode.md @@ -122,6 +122,31 @@ Add this to your `firebase.json`: } ``` +#### ASP.NET Core MVC + +Add this to your `Startup.cs`: + +```csharp +public void Configure(IApplicationBuilder app, IHostingEnvironment env) +{ + ... + app.Use(async (context, next) => + { + await next(); + + var path = context.Request.Path.Value; + + if (context.Response.StatusCode == (int)HttpStatusCode.NotFound && !Path.HasExtension(path) && !path.StartsWith("/api")) + { + context.Request.Path = "/Home"; + context.Response.StatusCode = (int)HttpStatusCode.OK; + await next(); + } + }); + ... +} +``` + ## Caveat There is a caveat to this: Your server will no longer report 404 errors as all not-found paths now serve up your `index.html` file. To get around the issue, you should implement a catch-all route within your Vue app to show a 404 page: