How to implement proper HTTP error handling in .NET MVC 2?

后端 未结 4 603
一个人的身影
一个人的身影 2020-11-29 19:29

I\'ve been struggling all day to implement error handling in my ASP.NET MVC 2 app. I\'ve looked at a variety of techniques, but none work properly. I\'m using MVC2 and .NET

4条回答
  •  春和景丽
    2020-11-29 19:45

    This doesn't answer your question, but it is important to note that HTTP status 500 indicates that something went wrong on the server, so your example:

    POST /User/New/new-user-name-too-long-for-db-column-constraint
    

    Is not valid grounds to throw a 500, its a data validation issue and should be handled by MVC data annotations or a jQuery validation framework or etc. Just showing an error message next to the TextBox saying "User Name too long" is much better.

提交回复
热议问题