我的站点在 asp.net mvc2 上运行,我使用 elmah 进行错误捕获,而不是 handlererror 属性
如果我浏览到一个不存在的页面,比如 'http://localhost:8095/Home/City/1/mtl/ko' 我收到 IIS 错误 404 页面
在 web.config 中我配置了我的自定义错误
我什至尝试在 global.asax application_error 中设置代码,但它并没有被困在那里
为什么我会收到 IIS 404 错误页面?
现在我想起来了,我想记录 404 错误,我应该在 asp.net mvc 的什么地方捕获这些错误?
谢谢
最佳答案
我知道这是一个老问题,但我想我会回答:
Elmah 具有您可以应用的过滤功能: http://code.google.com/p/elmah/wiki/ErrorFiltering
启用错误过滤后,您需要修改 Gloabal.asax.cs 以过滤错误:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("elmah.axd"); //Add this line to the register routes.
}
//ELMAH Filtering
protected void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs e)
{
FilterError404(e);
}
protected void ErrorMail_Filtering(object sender, ExceptionFilterEventArgs e)
{
FilterError404(e);
}
//Dimiss 404 errors for ELMAH
private void FilterError404(ExceptionFilterEventArgs e)
{
if (e.Exception.GetBaseException() is HttpException)
{
HttpException ex = (HttpException)e.Exception.GetBaseException();
if (ex.GetHttpCode() == 404)
{
e.Dismiss();
}
}
}
但坦率地说,我喜欢记录所有内容,包括 404 错误。这让我可以更好地了解用户如何尝试进入或发现需要支持的新功能。
其他资源: http://joel.net/logging-errors-with-elmah-in-asp.net-mvc-3--part-3--filtering http://ivanz.com/2011/05/08/asp-net-mvc-magical-error-logging-with-elmah/
关于asp.net mvc 2 customErrors iis 7.5 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4483840/