简体   繁体   English

在保持Web.Config安全的同时从WebMethod获取错误消息

[英]Getting error message from WebMethod while keeping Web.Config secure

I have a page that's doing jQuery Ajax calls to a WebMethod in one of my ASPX pages. 我的一个ASPX页面中有一个页面正在执行jQuery Ajax调用WebMethod。 In some cases, my WebMethod is throwing an exception with an error message. 在某些情况下,我的WebMethod抛出带有错误消息的异常。 This error message is really important for the UI, because it tells what to say to the user, so he can fix his form. 此错误消息对于UI确实很重要,因为它告诉用户要说的内容,以便用户可以修复其表单。

This is working fine in development environnement. 这在开发环境中运行良好。 But, in my production Web.Config, I need to keep customErrors set to "On", so I wont show important information. 但是,在我的生产Web.Config中,我需要将customErrors设置为“ On”,因此我不会显示重要信息。 Moreover, my IIS is overriding HTTP 500 errors too. 此外,我的IIS也覆盖了HTTP 500错误。

I tried the WebServices from ASMX, and it was working perfectly. 我尝试了ASMX的WebServices,它运行良好。 IIS wasn't overriding my HTTP 500, and customErrors was not hiding the message sent by the WebService. IIS没有覆盖我的HTTP 500,并且customErrors没有隐藏WebService发送的消息。 But migrating all my ASPX's WebMethods to ASMX files is not possible for now. 但是目前不可能将我所有的ASPX的WebMethods迁移到ASMX文件。

I'm looking for a guideline. 我正在寻找指南。 How my UI can gets my WebMethod's errors, while keeping my Web.Config safe for production? 我的UI如何在保持Web.Config安全进行生产的同时获取WebMethod的错误?

You should never show a yellow screen of death to a user. 切勿向用户显示死亡的黄屏。

Instead, consider implementing a Response object, contaning a boolean Success, an ErrorMessage (string) and the actual result data if needed. 相反,可以考虑实现Response对象,并在必要时包含布尔成功,错误消息(字符串)和实际结果数据。

You can then use a JavaScript callback and check if the call succeded. 然后,您可以使用JavaScript回调并检查调用是否成功。 If it did not, just alert() the error message. 如果没有,则只需发出error()错误消息。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM