ASP.Net中的AJAX Web服务-如何进行全局错误处理? [英] AJAX WebService in ASP.Net - how to global error handling?
问题描述
我的* .aspx站点中大约有50多个AJAX WebMethod,它由JQuery调用(有时是原始的jquery,有时是在lib之上)。
I have around 50+ AJAX WebMethods in my *.aspx site, which is called by JQuery (sometimes raw jquery, sometimes over lib's).
几个例子:
[WebMethod]
public static string GetLog()
{
DAL.LogService log = new DAL.LogService();
string items = log.GetLog();
return items;
}
[WebMethod]
public static void ClearBenchmarks()
{
DAL.LogService log = new DAL.LogService();
log.ClearBenchmarks();
}
[WebMethod]
public static void WriteLog(string message1, string message2, string user, string type)
{
DAL.LogService.WriteLog(message1, message2, user, type);
}
实际上,在大多数情况下,它们仅重定向到我应用程序的dataLayer ,但实际上,ofc上有50多个单一方法...
In fact in the most time, they only redirect to the dataLayer of my application, but in fact, ofc, I have 50+ single methods...
现在,我想在我的应用程序中包含错误处理-如何在不尝试的情况下进行全局操作捕获每种方法?
Now I want to include error handling in my application - how to do that globaly without having try catch in every single method?
推荐答案
这是.Net中的一个已知问题-global.asax的Application_Error永远不会在网络上触发服务。
This is a known issue in .Net - Application_Error of global.asax never fires for a web service.
所以您可以尝试遵循以下想法。
so you could try following ideas.
-
您可以在每种Web服务方法周围放置try-catch
you could place a try-catch around each web service method
使用外观设计模式并将try-catch包含在父
对象中
Use a facade design pattern and include the try-catch in parent objects
编写自定义SOAP扩展或HTTPModule
Write a custom SOAP extension or HTTPModule
希望这有帮助
这篇关于ASP.Net中的AJAX Web服务-如何进行全局错误处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!