显示的是自定义错误页面,而不是我的图像

问题描述 投票:0回答:1

我在项目中创建自定义错误页面后显示自定义错误页面,而不是在Project中找不到的所有图像。

例如:在我的项目中,我没有此路由“ localhost:44389 / help / 1”,并且当我在浏览器中显示“自定义错误页面”时,到目前为止,所有内容都是正确的,并且也是此数据源

<object class="price-popup__contact-info__row__icon" data="~/Landing/images/services/phone-icon.svg" type="image/svg+xml"></object>

不在我的根目录中,它显示了自定义错误页面,而不是未显示此图像。

如果需要我的一些代码,我会发送。

这是我的startup.cs

 public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {

        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
            app.UseStatusCodePagesWithRedirects("/Errors/{0}");
        }            
        app.UseHttpsRedirection();
        app.UseStaticFiles();
        app.UseRouting();
        app.UseAuthentication();
        app.UseAuthorization();
        app.UseMvc(routes =>
        {
            routes.MapRoute(
              name: "areas",
              template: "{area:exists}/{controller=Home}/{action=Index}/{id?}"
            );
            routes.MapRoute("Default", "{controller=Home}/{action=Index}/{id?}");
        });

    }

我该如何解决?

提前感谢

c# asp.net-core custom-error-pages
1个回答
0
投票
中没有此路由“ localhost:44389 / help / 1”

您可以添加自定义中间件来做到这一点,您只需要检查HTTP代码以查看是否存在错误:

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    app.Use(async (context, nextAction) => 
    {
        if(context.Response.StatusCode == 404)
        {
            await context.Response.WriteAsync("Sorry, it looks like we don't have a picture you requested");
            return;
        }
        await nextAction();
    }
    // rest of your services...
}

请参阅参考:Write custom ASP.NET Core middleware

© www.soinside.com 2019 - 2024. All rights reserved.