隐藏asp.net WebMethod返回的异常的stacktrace吗? [英] Hiding the stacktrace for an exception returned by a asp.net WebMethod?
问题描述
我在aspx页面中使用的属性为[WebMethod]的方法.我不使用任何asp.net ajax,但jQuery调用这些方法并以JSON返回对象.一切正常.
I am using methods with the Attribute [WebMethod] in my aspx pages. I don't use any asp.net ajax but jQuery to call these methods and return objects in JSON. This all works fine.
接下来,我在webMethod内添加了一个授权检查,如果当前用户无权访问此功能,则需要让调用JavaScript的人知道.
Next I added an authorization check inside the webMethod, if the current user doesn't have access to the feature I need to let the calling JavaScript know.
因此,我抛出了AccessViolationException异常,然后可以通过JavaScript中的OnError回调函数对其进行解析.这也可以,但是例外包括完整的StackTrace,我不想将其提供给调用客户端.
So I am throwing an AccessViolationException exception which can then be parsed by the OnError callback function in JavaScript. This works too but the exception includes the full StackTrace and I don't want to make this available to the calling client.
当WebMethod返回业务对象时,我还可以使用哪些其他方式将拒绝访问"返回给客户端?
What other ways I could use to return an "Access Denied" to the client when the WebMethod returns a business object?
我正在使用ASP.Net 3.5SP1和jQuery 1.32
I'm using ASP.Net 3.5SP1 and jQuery 1.32
推荐答案
为什么通过导线传播错误?为什么不使用错误响应?
Why propagate errors through the wire? why not use an error response ?
只需将您的对象包装在响应对象中,其中可能包含状态错误代码和向用户呈现的错误消息.
Just wrap your object in a response object wich can contain an error code for status and an error message to present to users.
这篇关于隐藏asp.net WebMethod返回的异常的stacktrace吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!