Skip to content

无效的404路由只显示Main,不显示菜单栏和标题栏 #3992

Answered by ArgoZhang
WeiJunFenYou asked this question in Q&A
Discussion options

You must be logged in to vote

@WeiJunFenYou net8 移除了 NotFound 模板,更改为使用 Error 页面

https://learn.microsoft.com/en-us/aspnet/core/fundamentals/error-handling?view=aspnetcore-8.0

所以目前就是这样的

if (app.Environment.IsDevelopment())
{
    app.UseDeveloperExceptionPage();
}
else
{
    app.UseExceptionHandler("/Error");
}

Error 页面里需要自己处理相关逻辑

public async Task OnGet()
{
    RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;

    var exception = HttpContext.Features.Get<IExceptionHandlerFeature>();
    if (exception?.Endpoint?.DisplayName == "/_Host" && exception?.Error is CryptographicException)
    {
        var adminUrl = await _dict.GetAdminUrl();
        if (!string.IsNullOrEmpty(adminUrl))
        {
            a…

Replies: 5 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
4 replies
@WeiJunFenYou
Comment options

@WeiJunFenYou
Comment options

@ArgoZhang
Comment options

@ArgoZhang
Comment options

Answer selected by WeiJunFenYou
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
bug Something isn't working
2 participants
Converted from issue

This discussion was converted from issue #3991 on August 06, 2024 16:17.