C# 如何获取aspx中哪个页面向Application_error抛出异常

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/344440/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 23:57:39  来源:igfitidea点击:

How to get which page threw an exception to Application_error in aspx

c#asp.netexceptionapplication-error

提问by user8456

I have a general exception handler, Application_error in my global.asax where I'm trying to isolate all the uncaught exceptions on all my many pages. I don't want to use Page_error to catch exception because it's inefficient to call that on so many pages. So where in the exception can I find what page actually caused the exception?

我有一个通用异常处理程序 Application_error 在我的 global.asax 中,我试图在我的所有页面上隔离所有未捕获的异常。我不想使用 Page_error 来捕获异常,因为在这么多页面上调用它是低效的。那么在异常中的哪里可以找到实际导致异常的页面?

采纳答案by jlew

HttpContext con = HttpContext.Current;
con.Request.Url.ToString()

回答by Joseph Ferris

Remember, the page is not (should not) always be the cause of the exception. It could just as easily be coming from another assembly - and if you don't have your logic in your codebehinds, it likely will be coming from another assembly. Don't get me wrong, it is great to know which page, from the aspect of saying X Page caused Y exception in Z assembly.

请记住,页面不是(不应该)总是导致异常的原因。它可能很容易来自另一个程序集 - 如果您的代码隐藏中没有您的逻辑,它很可能来自另一个程序集。不要误会我的意思,很高兴知道哪个页面,从说 X Page 导致 Z 程序集中的 Y 异常的方面来看。