How to make custom error pages work in ASP.NET MVC 4

前端 未结 11 2221
陌清茗
陌清茗 2020-11-22 12:25

I want a custom error page shown for 500, 404 and 403. Here\'s what I have done:

  1. Enabled custom errors in the web.config as follows:

    
    
            
11条回答
  •  [愿得一人]
    2020-11-22 13:20

    In web.config add this under system.webserver tag as below,

    
    
      
      
      
      
    
    

    and add a controller as,

    public class ErrorController : Controller
    {
        //
        // GET: /Error/
        [GET("/Error/NotFound")]
        public ActionResult NotFound()
        {
            Response.StatusCode = 404;
    
            return View();
        }
    
        [GET("/Error/ErrorPage")]
        public ActionResult ErrorPage()
        {
            Response.StatusCode = 500;
    
            return View();
        }
    }
    

    and add their respected views, this will work definitely I guess for all.

    This solution I found it from: Neptune Century

提交回复
热议问题