Handle validation failures myself in ASP.NET MVC

后端 未结 2 1981
心在旅途
心在旅途 2021-01-21 03:23

We all know that familiar ASP.NET error page that we see many times during development. To keep a consistent feel to my site, I\'d rather the user not see those errors, and hand

2条回答
  •  旧时难觅i
    2021-01-21 03:48

    Create a single base controller. Add [ValidateInput(false)] to the controller class:

     [ValidateInput(false)]
     public class BaseController : Controller
     {
    
     }
    

    And then update every controller to inherit from it:

     public class HomeController : BaseController
     {
    
     }
    

    I don't suggest turning off Request Validation myself but if you must, you can.

提交回复
热议问题