[英]ASP.NET: How to pass data to a custom error page
如何不使用Server.Transfer或某些重定向将某些数据从Global.asax事件处理程序传递到ASP.NET中的自定义错误页面?
Assuming you're catching unhandled exceptions in global.asax, I don't think you can. 假设您在global.asax中捕获了未处理的异常,我认为您不能。 You're no longer in anyone's session at that point, so you've lost just about all connection with the error, other than the exception itself.
那时您不再处于任何人的会话中,因此除了异常本身之外,您几乎已经失去了与错误的所有联系。
You might try catching unhandled exceptions in each page, by adding a handler for the Page_Error event. 您可以尝试通过为Page_Error事件添加处理程序来捕获每个页面中未处理的异常。 You can centralize some of that by having each page subclass your own application "page base" class instead of System.Web.UI.Page, and make sure that your "page base" class inherits from System.Web.UI.Page.
您可以通过让每个页面子类成为您自己的应用程序“页面基础”类而不是System.Web.UI.Page来集中其中的某些内容,并确保“页面基础”类继承自System.Web.UI.Page。 Then have your page base class handle Page_Error.
然后让您的页面基类处理Page_Error。 But you won't be in page-specific code at that point, so you'll still have to figure out a method for passing data to that custom error page.
但是那时候您将不会使用特定于页面的代码,因此您仍然必须找出一种将数据传递到该自定义错误页面的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.