通过 PageMethods & 将 JQuery 脚本错误记录到 ASP.NET 服务器AJAX 调用

发布于 2024-10-09 06:04:54 字数 484 浏览 1 评论 0原文

我正在开发一个在客户端使用 JQuery 并在服务器上使用 ASP.NET/C# 和 PageMethods 的网站。

我正在寻找一些关于在服务器上记录 JavaScript 错误的建议。

我的计划是在我的基页中有一些通用的 PageMethods ,如果我的 JQuery 代码中的 try/catch 块中发生错误,我将调用 PageMethod 并传递函数名称、用户上下文和其他相关参数(如 JSON 字符串、变量等)。

显然,我只能对 try/catch 块中捕获的错误执行此操作。

此处提出了类似的问题,但那是 6 个多月前的事了。

我正在考虑服务器上的 Log4Net 和本机 .NET 日志记录功能。

I'm working on a website that uses JQuery on the client and ASP.NET/C# and PageMethods on the server.

I'm looking for some suggestions for logging JavaScript errors on the server.

My plan is to have some general-purpose PageMethods in my base page, and if an error occurs in a try/catch block in my JQuery code, I'll call the PageMethod and pass up the function name, user context, and other relevant params (like JSON strings, variables, etc).

Obviously, I'll only be able to do this for errors that are caught in a try/catch block.

A similar question was posed here but that was more than 6 months ago.

I'm considering both Log4Net and native .NET logging capabilities on the server.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月野兔 2024-10-16 06:04:54

当您可以使用简单的方法(例如对服务器的异步调用)来完成此操作时,我不太喜欢使用 log4net 和其他工具。

我建议你创建一个处理程序来处理 JS 中的所有错误,并使用 jquery.ajax () (http://api.jquery.com/jQuery.ajax/) 并在服务器上对其进行异步调用处理这些错误并使用服务器上的错误记录器处理它。

听起来不错吗?

您应该避免学习新工具并避免增加复杂性,因为如果突然出现任何错误,您现在依赖于该工具的支持。

I am not a big fan of using log4net and other tools when you can do it using simple methods like an async call to the server.

what I would suggest is you create a handler to handle all your errors in JS and make an async call to it using jquery.ajax () (http://api.jquery.com/jQuery.ajax/) and at the server you handle these errors and handle it with your error logger on server.

Does that sound good?

You should avoid learning new tools and adding to the complication cos if suddenly there are any errors you are now dependent on the support for that tool.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文