AJAX WebService in ASP.Net - how to global error handling? [duplicate]

孤者浪人 提交于 2019-12-10 14:10:09

问题


I have around 50+ AJAX WebMethods in my *.aspx site, which is called by JQuery (sometimes raw jquery, sometimes over lib's).

Here are a few examples:

 [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);
    }

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?


回答1:


This is a known issue in .Net - Application_Error of global.asax never fires for a web service.

so you could try following ideas.

  1. you could place a try-catch around each web service method

  2. Use a facade design pattern and include the try-catch in parent objects

  3. Write a custom SOAP extension or HTTPModule

Hope this helps



来源:https://stackoverflow.com/questions/29606617/ajax-webservice-in-asp-net-how-to-global-error-handling

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!