Application_Error 未触发
我无法在 global.asax 中触发我的 Application_Error 方法。我在 Application_Error 函数的第一行放置了一个断点,但它永远不会在那里中断。相反,服务器返回通常的黄色格式的堆栈跟踪页面,并说“发生了未处理的异常......”,所以我知道正在抛出异常。
有什么建议吗?我正在使用 VS2010、C# 4.0,并在 Dev Web 服务器中运行它(通过 F5)。
当 Application_Error 被跳过时我看到的Global.asax
void Application_Error(object sender, EventArgs e)
{
int i;
i = 3; <==BREAKPOINT SET HERE, NEVER HITS
}
web.config
<customErrors mode="Off" />
...
<compilation debug="true" targetFramework="4.0">
页面:
Server Error in '/' Application.
--------------------------------------------------------------------------------
Invalid column name 'JobTypeID'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Invalid column name 'JobTypeID'.
Source Error:
Line 95:
Line 96: MyEntities context = Util.CurrentMasterContext();
Line 97: UserRec = context.User
Line 98: .Include("Person")
Line 99: .Include("AccountType")
I'm not able to get my Application_Error method to fire in global.asax. I've placed a breakpoint in the first line of my Application_Error function but it never breaks there. Instead, the server is returning the usual yellow formatted stack trace page and saying that "An unhandled exception occurred...." so I know an exception is being thrown.
Any advice? I'm using VS2010, C# 4.0, and running this in the Dev web server (via F5).
Global.asax
void Application_Error(object sender, EventArgs e)
{
int i;
i = 3; <==BREAKPOINT SET HERE, NEVER HITS
}
web.config
<customErrors mode="Off" />
...
<compilation debug="true" targetFramework="4.0">
Page that I see when Application_Error gets skipped:
Server Error in '/' Application.
--------------------------------------------------------------------------------
Invalid column name 'JobTypeID'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Invalid column name 'JobTypeID'.
Source Error:
Line 95:
Line 96: MyEntities context = Util.CurrentMasterContext();
Line 97: UserRec = context.User
Line 98: .Include("Person")
Line 99: .Include("AccountType")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我记得(意识到)我有一个自定义的 HttpModule。该处理程序没有为 Error 事件实现事件处理程序,因此我添加了一个,瞧,这确实触发了。
但现在我的问题发生了变化:如果您注册一个自定义 HttpModule,这是否会导致在 global.asax 级别触发所有事件,甚至是您的 HttpModule 未处理的那些事件?
这对任何人来说都有意义吗?
Ok, I remembered (realized) that I had a custom HttpModule. This handler was not implementing an event handler for the Error event so I added one and voila, this did fire.
But now my question has changed: if you register a custom HttpModule does this defeat the firing of all events at the global.asax level, even those events that your HttpModule isn't handling?
Does that make sense to any one?