Skip to content

Commit ed22793

Browse files
authored
doc(404): add not found middleware (#4615)
* doc: 增加 404 重定向 * refactor: 修复 301 重定向问题
1 parent f099365 commit ed22793

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/BootstrapBlazor.Server/Program.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@
4141

4242
var app = builder.Build();
4343

44+
app.UseStatusCodePages(context =>
45+
{
46+
var response = context.HttpContext.Response;
47+
if(response.StatusCode == 404)
48+
{
49+
response.Redirect("/", true);
50+
}
51+
return Task.CompletedTask;
52+
});
53+
4454
// 启用本地化
4555
var option = app.Services.GetService<IOptions<RequestLocalizationOptions>>();
4656
if (option != null)

0 commit comments

Comments
 (0)