从客户端的 ASP.NET PageMethods 获取异常详细信息
我有一个 pagemethod,我可以从 JavaScript 调用它 说
Pagemethods.MyMethod(MyParameter, onsucess, onfailure);
在后面的代码中,我有这样的内容:
[WebMethod]
public static void MyMethod(Param)
{
try{
//DoSomething..
}
catch(exception ex)
{
//Log the exception and rethrow
throw new exception(ex.innerexception);
}
}
现在我面临的问题是:
每当我确实遇到异常时, 我从后面的代码中重新抛出异常
但是在 onfailure 方法中,我只是收到一条通用消息说 “服务器方法 MyMethod 因以下错误而失败:”
我似乎没有获取异常详细信息,而只获取通用异常,
我如何获取 JavaScript 上的异常详细信息,以便根据 UI/JavaScript 端处理它。
我已经验证,这不是 web.config 中自定义错误设置的问题。
有人可以告诉我这里发生了什么吗?
PS:我已经单步执行了每一行代码,并且记录后的异常会使用正确的异常详细信息(即消息)重新抛出。
I am having a pagemethod to which i give a call from my JavaScript
say
Pagemethods.MyMethod(MyParameter, onsucess, onfailure);
In the Code behind, I have something like this:
[WebMethod]
public static void MyMethod(Param)
{
try{
//DoSomething..
}
catch(exception ex)
{
//Log the exception and rethrow
throw new exception(ex.innerexception);
}
}
Now the issue i face is :
Whenever i do get an exception,
i re throw the exception from code behind
But in the onfailure method, i just get a generic message saying that
"the server method MyMethod failed with following error: "
I don't seem to get the exception details and only that generic exception,
How can i get the exception details on JavaScript, in order to handle it according on the UI/JavaScript side.
I have verified, that it is not an issue with custom errors settings in web.config.
Can some one enlighten to me as to what is happening here?
PS: i have stepped through each and every line of code and the exception after being logged is rethrown with the proper exception details i.e. message.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我了解,只要您
的 web.config 中包含该消息,该消息就会返回给客户端。 你确定有这个设置吗?
要显示与错误相关的消息,您需要将函数名称作为页面方法调用的第三个参数:该函数可以简单如下:
这就是我们所拥有的,并且工作正常
As far as I understand as long as you have
in your web.config, the message will be returned to client. Are you sure you have this setting ?
To display the message associated with error you need to have oassed the name of the function as the third parameter of the page method call : this function could be as simple as:
That's what we have and it works OK
在 web.config 的
部分设置
后,尝试这些函数来获取所有PageMethod 的 onfailure 的异常详细信息:我发现错误的状态代码比错误消息本身更有帮助。
After you have set
<customErrors mode="off" />
in the<system.web>
section of the web.config, try these functions to get all of the exception details from the PageMethod's onfailure:I've found the error's status code to be far more helpful than the error message itself.