如何在我的 MVC 应用程序有机会处理它之前阻止 IIS7 推出自己的 404? [英] How do I stop IIS7 from putting out its own 404 before my MVC app gets a chance to handle it?

查看:18
本文介绍了如何在我的 MVC 应用程序有机会处理它之前阻止 IIS7 推出自己的 404?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 ASP.NET MVC 2 应用程序,它在 global.asax 中有一个 Application_Error 事件处理程序.在此,我正在检测异常类型为 HttpException 且 HTTP 代码为 404 的情况,并重定向到我自己的 404 处理页面.

I have an ASP.NET MVC 2 application, which has an Application_Error event handler in global.asax. In this, I'm detecting the case where the Exception type is HttpException and the HTTP code is 404, and redirecting to my own 404-handling page.

这在我的 Cassini 开发服务器上运行良好,但现在我正尝试将其移至具有 IIS7 的生产服务器(使用集成模式).

This works fine on my Cassini development server, but now I'm trying to move it over to my production server which has IIS7 (using integrated mode).

当我请求一个不存在的 URL 时,IIS7 显示它自己的 404 页面,据我所知,我的 Application_Error 方法从未被调用.

When I request a non-existent URL, IIS7 is showing its own 404 page, and so far as I can tell, my Application_Error method is never called.

我该如何解决这个问题?

How do I fix that?

推荐答案

我在另一个帖子中回答了这个问题:托管在 IIS7 上的 ASP.NET 应用程序忽略自定义错误并回退到 IIS 错误

I answered that in another post: ASP.NET Application hosted on IIS7 that is ignoring custom errors and falls back to IIS errors

"要禁用您必须设置的 IIS 错误消息

"To disable the IIS error messages you have to set

  Response.TrySkipIisCustomErrors = true;

在您的错误页面中.之后,您的错误消息应该没有问题地显示."

in your error page. After that, your Error messages should show without problem."

这篇关于如何在我的 MVC 应用程序有机会处理它之前阻止 IIS7 推出自己的 404?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆