充分利用ASP.NET PageMethods异常详细信息在客户端 [英] Getting Exception Details from ASP.NET PageMethods on the Client SIde
问题描述
我有一个PageMethod的,而我给从我的JavaScript调用
说
I am having a pagemethod to which i give a call from my JavaScript say
Pagemethods.MyMethod(MyParameter, onsucess, onfailure);
在code后面,我有这样的事情:
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);
}
}
现在我面临的问题是:
每当我得到一个异常,
我再扔从code中的例外后面
Whenever i do get an exception, i re throw the exception from code behind
但在onFailure处的方法,我只是得到一个通用的消息说,
服务器的方法的MyMethod失败,以下错误:
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,
我怎样才能JavaScript的异常的详细信息,以便根据它的用户界面来处理/ JavaScript端。
How can i get the exception details on JavaScript, in order to handle it according on the UI/JavaScript side.
我已经验证了,这不是在web.config中的自定义错误设置的问题。
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:我已经通过code和异常每踩线被记录被重新抛出用适当的异常详细信息后,即信息
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.
推荐答案
至于我,只要你明白
<customErrors mode="off" />
在你的web.config,该消息将返回到客户端。你确定你有这样的设置?
in your web.config, the message will be returned to client. Are you sure you have this setting ?
要显示你需要有oassed功能的页面方法调用的第三个参数的名称错误关联的消息:这个功能可以简单:
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:
function onfailure( result )
{
alert( result.get_message() );
}
这就是我们所拥有的,它的工作原理确定
That's what we have and it works OK
这篇关于充分利用ASP.NET PageMethods异常详细信息在客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!