MVC 6 404 Not Found

前端 未结 6 1472
我在风中等你
我在风中等你 2020-12-06 12:04

Instead of getting a HTTP 404 response, I\'d like to have a generic 404 Not Found page (HTTP 200). I know you can set that up in MVC 5 with



        
6条回答
  •  攒了一身酷
    2020-12-06 12:43

    In the Configure function of the Startup class, call:

    app.UseErrorPage(ErrorPageOptions.ShowAll);
    

    more production ready:

        if (string.Equals(env.EnvironmentName, "Development", StringComparison.OrdinalIgnoreCase))
        {
            app.UseBrowserLink();
            app.UseErrorPage(ErrorPageOptions.ShowAll);
            app.UseDatabaseErrorPage(DatabaseErrorPageOptions.ShowAll);
        }
        else
        {
            // Add Error handling middleware which catches all application specific errors and
            // send the request to the following path or controller action.
            app.UseErrorHandler("/Home/Error");
        }
    

提交回复
热议问题