【发布时间】:2016-03-17 16:47:23
【问题描述】:
当我对 API 进行 $http 调用时,它会从我的 MVC 控制器中引发异常,我会使用
记录返回到我的 Angular 代码的异常消息.then(function success(response){ // success },
function error(response){ console.log(JSON.stringify(response);};})
这可行,并显示自定义异常消息。但是,当我在 IIS 上的远程服务器上部署应用程序时,抛出异常时,response 参数始终为:
{"data":{"Message":"An error has occurred."},"status":500,"config":{"method":"GET","transformRequest":[null],"transformResponse":[null],"url":...,"headers":{"Accept":"application/json, text/plain, */*"}},"statusText":"Internal Server Error"}
...基本上,它不包含自定义异常消息,它总是简单地显示“发生错误”。
这可能是一个路由错误,也就是异常实际上并没有到达我的 Angular 端吗?我背后的逻辑是因为远程 URL 看起来像:
website.com/extension ,在我的本地是 website.com
【问题讨论】:
-
尝试直接在浏览器中访问 API 并查看它是否有效。如果没有,请检查您的 IIS 日志。
-
堆栈跟踪错误仅在本地显示,除非您在 web.config 上更改它:technet.microsoft.com/en-us/library/bb684665.aspx
-
无法检查自动柜员机的日志,只要有能力就行。就像你说的,我尝试了
website.com/extension/api/controller/action,它返回了一个带有错误标记中的消息的 XML。当我从website.com/api/controller/action执行此操作时,我在错误标记中得到 Message、ExceptionMessage、ExceptionType 和 StackTrace……看起来它出于某种原因正在切断这些额外的属性。 -
@Gusman 哦,我明白了。谢谢!
标签: c# asp.net angularjs asp.net-mvc exception