当应用程序位于远程计算机上时,未定义异常 [英] Exception is undefined when app is on remote machine
问题描述
当我对API进行$ http调用时,它从我的MVC控制器抛出异常,我用
When I make an $http call to API, and it throws an exception from my MVC controller, I log the exception message that is returned to my Angular code with
.then(function success(response){ // success },
function error(response){ console.log(JSON.stringify(response);};})
这有效,并且显示自定义异常消息.但是,当我在IIS上的远程服务器上部署应用程序时,抛出异常时,response
参数始终为:
This works and the custom exception message is displayed. However when I deploy the app on a remote server on IIS, when an exception is thrown, the response
parameter is always:
{"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"}
...基本上,它不包含自定义的Exception消息,它将始终只是显示发生了错误".
...basically, it doesn't contain the custom Exception message, it will always simply have "An error has occurred."
这可能是一个路由错误,也就是异常实际上没有到达我的Angular端吗?我这样做的逻辑是因为远程URL看起来像:
Could this be a routing error, a.k.a the exception doesn't actually reach my Angular side? My logic behind this is because the remote URL looks like:
website.com/extension
,在我的本地是website.com
推荐答案
默认情况下,出于安全原因,从远程计算机访问时,完整的错误消息不会发送到客户端,因为它可能会泄露敏感数据.您可以通过将customErrors
模式设置为Off
来修改web.config
,以将详细信息返回到远程计算机.但是,您应该首先考虑安全隐患.
By default, for security reasons, the full error message is not sent to the client when accessed from a remote machine as it could reveal sensitive data. You can modify the web.config
to return the details to remote machines by setting the customErrors
mode to Off
. However, you should not do so without considering the security implications first.
<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>
更好的做法是向客户端提供通用错误消息对不起,发生了意外错误!"并在日志中记录服务器上的实际错误消息.
A better practice is to give a generic error message to the client "Sorry, an unexpected error has occurred!" and record the actual error message on the server in your logs.
这篇关于当应用程序位于远程计算机上时,未定义异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!