迁移到 IIS 7 上的 ASP.NET 4.0,无法使自定义错误正常工作
我有一个用于面向 ASP.NET 2.0 的 ASP.NET Web 应用程序项目。我在托管 Web 应用程序的 Web 服务器上安装了 ASP.NET 4.0,并将 Web 应用程序项目更改为面向 .NET 4.0。一切正常,但有例外:自定义错误处理
在迁移到 .NET 4.0 之前,自定义错误曾经可以正常工作。在我的应用程序中,我有一个带有全局应用程序错误处理程序的 Global.asax 页面,该页面在我的开发环境中运行良好(并且在服务器上的 .NET 2.0 中也运行良好),但它不适用于带有 . NET 4.0 设置。我在 web.config 文件中还有一个 customErrors 部分,该部分应该将浏览器重定向到自定义错误页面,以防错误导致全局应用程序处理程序失败。这在我的机器上也运行良好,但在服务器上无法执行任何操作。我确实尝试了 mode 属性的所有三种不同设置。
如果有人知道为什么会发生这种情况,我将不胜感激!
I have an ASP.NET Web Application project that used to target ASP.NET 2.0. I installed ASP.NET 4.0 on the web server hosting the web application and changed the web application project to target .NET 4.0. Everything works ok with on exception: Custom Error Handling
Before migrating to .NET 4.0, custom errors used to work. In my application I have a Global.asax page with a global application error handler which works fine on my development environment (and worked just fine with .NET 2.0 on the server as well) which doesn't work with the new IIS 7 with .NET 4.0 setup. I also have a customErrors section in the web.config file which is supposed redirect the browser to a custom error page in case the error was such that even the global application handler would fail. That also works fine on my machine, but fails to do anything on the server. And I did try all three different settings for the mode attribute.
If anyone has any idea why this might be happening I'd appreciate any feedback!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这仍然有点神秘,但这是我发现的。我的错误处理程序都已触发,重定向也像以前一样发生,但当请求最终传输到错误处理程序 .aspx 页面(通过 Server.Transfer)时,它正在死亡。原因是在 ErrorHandler.aspx 页面上,我将 HTTP 响应代码设置为 200,尝试不发回实际的 HTTP 错误代码,而只是显示一条友好的消息。当我注释掉将 HTTP 状态代码设置为 200 的代码后,一切都开始正常工作,几乎就像迁移到 .NET 4.0 之前一样。
我仍然不确定为什么尝试将 HTTP 状态代码设置为 200 会导致奇怪的行为,但我很高兴我找到了它,纠正了问题并可以继续我的生活。
This one is still a bit mysterious but here's what I found. My error handlers were all firing, and the redirects were happening just as before but when the request was finally transferred to the error handler .aspx page (via a Server.Transfer) it was dying. The reason for that was that on the ErrorHandler.aspx page, I was setting the HTTP response code to 200, trying not to send back an actual HTTP error code, and instead to simply display a friendly message. Once I commented out the code that was setting the HTTP Status code to 200, all started working fine and almost like before the move to .NET 4.0.
I'm still not sure why attempting to set the HTTP Status code to 200 was causing the strange behavior, but I'm glad I found it, corrected the problem and could get on with my life..