简体   繁体   English

如何在ASP.NET中处理WCF异常

[英]How to handle WCF exceptions in ASP.NET

I'm working on a traditional ASP.NET application making WCF service calls. 我正在做一个传统的ASP.NET应用程序,进行WCF服务调用。

Should I put a try catch around the WCF call and display the error details at the top of the current page; 我应该试一下WCF调用并在当前页面顶部显示错误详细信息吗? let the error redirect the user to a custom error page; 让错误将用户重定向到自定义错误页面; or leave it up IIS / .NET framework? 还是将其保留在IIS / .NET框架中?

Which approach is least likely to confuse future developer? 哪种方法最不可能使未来的开发人员感到困惑?

Never to the yellow screen of death. 永远不要到死亡的黄屏。 The detailed information about the error can give hints to a hacker to break your site. 有关该错误的详细信息可以提示黑客破坏您的网站。

If the page cannot be displayed without the service request, then redirect to a custom error page. 如果在没有服务请求的情况下无法显示该页面,请重定向到自定义错误页面。

If only a small portion of information will be missing on a page which is not key to its function, then better display a friendly message to the user that this particular piece of information is not available at the moment. 如果页面上只有一小部分信息丢失,而这并不是对其功能的关键,则可以更好地向用户显示一条友好的消息,即该信息暂时不可用。

This will depend on your application requirements. 这将取决于您的应用程序要求。 Can you continue processing if the web service call fails? 如果Web服务调用失败,您可以继续处理吗? If not you probably should log the exception and redirect the user to a 500 page. 如果不是这样,您可能应该记录该异常并将用户重定向到500页。 I would use Application_Error method in global.asax to do this. 我会在global.asax中使用Application_Error方法来执行此操作。 If you can continue the processing then you should put a try/catch around your web service call and handle the appropriate FaultException. 如果可以继续处理,则应在Web服务调用周围进行try / catch并处理适当的FaultException。 You should never let customers see the yellow screen in production. 您绝对不应让客户看到生产中的黄屏。

If you expect that the WCF call can throw an exception and you know which exception types you can get, then yes, you should catch the exception and perform the appropriate action. 如果您希望WCF调用可以引发异常,并且知道可以获取的异常类型,那么可以,您应该捕获该异常并执行适当的操作。 Usually it is a good idea to tell the user just that an error made the operation to fail, and log the exception detail for further examination by you or the technical support. 通常,最好是告诉用户错误导致操作失败,并记录异常详细信息以供您或技术支持进一步检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Silverlight 4和ASP.NET的WCF故障异常 - WCF Fault Exceptions with Silverlight 4 and ASP.NET 如何在ASP.Net Webform中处理和“显示”页面级异常 - How to handle and **display** page level exceptions in ASP.Net Webform 如何处理自己的ASP.NET用户控件中引发的异常? - How to handle exceptions thrown in own ASP.NET user control? 如何在ASP.NET请求生命周期中处理异常 - How to handle exceptions during an ASP.NET request lifecycle ASP.NET如何处理未处理的异常? - How does ASP.NET handle unhandled exceptions? 如何在ASP.NET MVC中处理“默认”异常? - How to handle “default” exceptions in ASP.NET MVC? 处理asp.net中未处理的异常 - Handle unhandled exceptions in asp.net 如何在ASP.NET中处理表单身份验证超时异常? - How can I handle forms authentication timeout exceptions in ASP.NET? 如何在服务器端捕获 ASP.NET Core 2 SignalR 异常并在客户端使用 JavaScript 处理它们? - How to catch ASP.NET Core 2 SignalR exceptions on server-side and handle them on client side with JavaScript? 当通过lambda表达式引发异常时,如何在asp.net web api中全局处理异常 - How to globally handle exceptions in asp.net web api when exception is raised through lambda expression
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM