. NET WebAPI correctly throws error details

Source: Internet
Author: User

Recently published the previous WEBAPI project to the server, the database from SQL Server2008 Express to SQL Server2000, but the paging query when the server throws a "500 error", but do not see the details of the error, according to previous experience to the configuration file customErrors Open still do not see the details, because the project is published on the server, there is no way to debug, and the server is windows20003, the page has no way to debug remotely, write Try...catch ... Catch the error in action and throw still get no details, no error details, no direction to modify the error, and then search the solution on the Internet, found that Webapi error, only throws 500, does not contain the details, The only way to get the details of the error is to throw the httpresponseexception, and the code is as follows:

Try{    ...}Catch(Exception e) {//it must be thrown in Webapi to throw an exception, otherwise it throws a default 500 exception    varRESP =NewHttpresponsemessage (httpstatuscode.internalservererror) {Content=Newstringcontent (E.tostring ()), Reasonphrase="Error"    }; Throw Newhttpresponseexception (RESP);}

Finally, according to the error details found that the new version of NHibernate does not support SQL Server2000 paged query, and installed a SQL Server2005 error resolution.

Just in writing this record time just think that actually need not so troublesome, can direct the exception detailed content output, and detours ...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.