开发者

HandleError - how do you display exception message in error page?

开发者 https://www.devze.com 2023-03-31 13:21 出处:网络
I have the following on my base controller class which my other controllers inherit from: [HandleError(ExceptionType = typeof(NotFoundException), View = \"NotFound\")]

I have the following on my base controller class which my other controllers inherit from:

[HandleError(ExceptionType = typeof(NotFoundException), View = "NotFound")]
[HandleError(ExceptionType = typeof(UnauthorisedException), View = "Unauthorised")]
开发者_StackOverflow

I would like to be able to add the exception message into the view. So for example when I throw an exception:

throw new NotFoundException("This record was not found");

I could somehow grab this message and insert it into the NotFound view.


The exception object is send in the HandleErrorInfo that is the model of the error page. You can display the exception message with:

<%: Model.Exception.Message %>

If you want the complete information with the stack trace and everything, you can just use the ToString method (which is implicitly called on non-string objects that you output):

<%: Model.Exception %>
0

精彩评论

暂无评论...
验证码 换一张
取 消